Python 3 support #44

merged 12 commits into from Apr 27, 2012


None yet
3 participants

dougalsutherland commented Apr 27, 2012

These changes tweak the syntax of the pure-Python components of the code to be compatible with both Python 2 and 3, as well as accounting for some semantic changes. Luckily, Cython's syntactic chimerism means that most of the code could stay unchanged.

The only change that has any negative impact on Python 2 is that there are now some instances of list(range), which needlessly copies the list created by range; this only happens in the template code and some testing code, and never with big lists (I think only ever on range(ary.ndim)), so it shouldn't be too bad.

I've successfully made the templates, built the library, and run bn.test() and bn.bench() with Python 2.6, 2.7, and 3.2 on OSX, as well as with Python 2.6, 2.7, and 3.2 on Debian. Python 2.5 works the same on Debian as it did before (two test failures because nanargmin and nanargmax disagree on what should happen when an entire row is nan; bench completes succesfully).

Someone should test on Windows, and I haven't verified that output is identical between 2.* and 3.*, but I think this should otherwise be ready to merge.

dougalsutherland added some commits Apr 26, 2012

make range(...) + [None] work in python3
note that though this works in python2 also, it involves a pointless
copy; this is just in test code though, so it's probably fine.
python3 compatability for range() in slow funcs
all uses of range in the slow functions now look fine as either lists or
range objects (though the range(ndim)[axis] calls could be done more
slow rankdata/nanrankdata should use np.asarray
The other slow functions do this, and it was causing a test failure in
Python 3 when called with [] (since it tried to access .ndim, which
doesn't exist). I don't know why this isn't an error in Python 2...?

kwgoodman commented Apr 27, 2012

This is amazing! Thank you so much.

I'll make sure it gets tested on windows before merging.

Could you make one more commit?

  • Add a comment about Python 3 (3.2?) support in the release.rst file (first item under enhancements)
  • In readme.rst bump required python from 2.5, 2.6, 2.7 to 2.6, 2.7, 3.2(?)
  • In add "Programming Language :: Python :: 3" as second to last entry in CLASSIFIERS list

This is a big improvement to bottleneck.


kwgoodman commented Apr 27, 2012

It works on windows. But Christoph said the pyx files didn't build on python 3 using the command:

python -c "from bottleneck.src.makepyx import makepyx; makepyx()"

So he built the pyx files with python 2. Users don't typically build their own pyx files since I include the C files in the source distribution so I think that should be OK.

I installed python 3.2 on my ubuntu box. All tests passed and bn.bench() ran.

Again, very nice work!

kwgoodman added a commit that referenced this pull request Apr 27, 2012

@kwgoodman kwgoodman merged commit 2f07774 into kwgoodman:master Apr 27, 2012


dougalsutherland commented Apr 27, 2012

Do you know what the errors were in building the pyx files? I was able to build them in 3.2 on Linux/Mac after 9f3c623 (which I made today, so maybe he pulled before that).


cgohlke commented Apr 27, 2012

I did pull before 9f3c623, which should fix this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "bottleneck\src\", line 3, in <module>
    from bottleneck.src.template.func.func import funcpyx
  File "bottleneck\src\template\func\", line 6, in <module>
    from median import median
ImportError: No module named median

kwgoodman commented Apr 27, 2012

That is good news.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment