[Numpy-discussion] Please keep Numpy master working on Py3

Pauli Virtanen pav at iki.fi
Tue Feb 1 20:11:19 EST 2011

On Tue, 01 Feb 2011 16:42:04 -0800, Mark Wiebe wrote:
[clip: problem 1]
> This looks like it's a problem in new_iterator_pywrap.c, in
> PySequenceMethods npyiter_as_sequence.  I got this error when trying to
> slice before implementing the slot sq_slice.  I copied the definition
> from array_as_sequence, which I thought would already have any
> adjustments for Py3.  The value in that slot shouldn't be NULL, though,
> so I don't know why it's giving the error, maybe the struct definition
> changed, and somehow in the array sequence methods that gets masked?  Or
> maybe the assignment slice slot needs to be filled as well, but that
> doesn't seem right to me.

The slot sq_slice is in the struct on Python 3, but the entry is a dummy 

It appears slices are supposed to be handled in PyMappingMethod. (If you 
walk through the __getitem__ code for ndarray, you'll note that if it 
encounters a single slice, it falls back to calling the PySequence 
methods :O)

The Python C-API docs don't seem to say much on the status of sq_slice on 
Python 2, but at least on the Python side I know that the corresponding 
__*slice__ hooks are deprecated in favor of the __*item__ routines since 
Python 2.6.

[clip: problem 2]
> I see, in Py3 oct and hex call array_index instead of array_oct and
> array_hex.  

This is because the __oct__ and __hex__ C-slots were removed from 
PyNumberMethods on Py3.

> I think changing the self-reference exceptions in
> int/long/float/oct/hex to TypeError instead of ValueError is probably 
> a good way to make this consistent.

Probably a good idea, since the other errors there are also TypeErrors.


More information about the NumPy-Discussion mailing list