[pymvpa] PyMVPA for Python 3 -- second report

Tiziano Zito opossumnano at gmail.com
Sat Apr 21 08:18:02 UTC 2012


> may be some skype/shared screen
> sprintee next week over remaining issues etc?

yes, if michael is around we could meet in berlin or magdeburg and
have get you on skype. 

> There is a bulk of changes in some guys feature branches and if we do not
> merge now, later it might not be as easy ;) I guess I would also need to check
> how changes affect minimal compatible version in 2.x series (if affect at all).
> FWIC (for what i care) 2.6 should be good enough for me ;)

I have tried to stay compatible with 2.5 so that you can backport to
squeeze, but I did not test if this is really the case.

> but at times going through changes I got a bit scared ;-) e.g.

that is the most controversial change, I think:

> 1.
> -            self._unique_values = np.unique(self.value)
> +            # get a 1-D array
> +            arrvalue = np.asarray(self.value).ravel()
> +            # check if we have None somewhere
> +            nones = np.equal(arrvalue, None)
> +            if nones.any():
> +                uniques = np.unique(arrvalue[nones == False])
> +                # put back one None
> +                self._unique_values = np.insert(uniques, 0, None)
> +            else:
> +                self._unique_values = np.unique(arrvalue)
> 
> does numpy  handles its own arrays differently among pythons or what is
> the reason?

the reason is that sometimes self.values contains None's. in python
3 arithmetic comparisons like < or > are not allowed among
heterogeneous types, so you can not sort a list or an array that
looks for example like this: [ 0, 1, None, -2]. and np.unique uses
sort internally. the dance with the None's is not needed in py2, so
we could special case with a sys.version >= '3', but you have to
decide if it is worth it. the new masked array type in newcoming
numpy could probably used instead...

it is not an inferior behaviour when compared to py2: actually I
think I spotted at least one place (the tests is still failing)
where PyMVPA was comparing non-comparable types and getting a
basically random result:

======================================================================
ERROR: test_basic (mvpa2.tests.test_datameasure.SensitivityAnalysersTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tiziano/git/PyMVPA/build/py3k/mvpa2/testing/sweepargs.py", line 67
, in do_sweep
    method(*args_, **kwargs_)
  File "/home/tiziano/git/PyMVPA/build/py3k/mvpa2/tests/test_datameasure.py", li
ne 79, in test_basic
    self.assertTrue(f[0] > 0.1)     # some reasonably large value
TypeError: unorderable types: Dataset() > float()

> 2.
> -        sample += random.sample((targets == r).nonzero()[0], npertarget[i] )
> +        sample += random.sample(list((targets == r).nonzero()[0]), npertarget[i] )
> 
> why does it need explicit conversion to list, are numpy arrays not
> iterables any longer, or random.sample now can't tollerate them...

the reason is:

Python 3.2.3rc2 (default, Mar 21 2012, 05:47:04) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> x = numpy.zeros((10,))
>>> import random
>>> random.sample(x, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/random.py", line 298, in sample
    raise TypeError("Population must be a sequence or set.  For dicts, use list(d).")
TypeError: Population must be a sequence or set.  For dicts, use list(d).
>>> 

I do not know why numpy arrays are not sequences in py3, but this is
it.

> +Convert *py files with lib2to3.
> +Taken from MDP and numpy.
> 
> so -- copyright of numpy and MDP developers? years? (BSD-3 I guess ;) )

will do :)

ciao,
tiziano




More information about the Pkg-ExpPsy-PyMVPA mailing list