[Numpy-discussion] indexing bug?

Christopher Barker Chris.Barker@noaa....
Wed Oct 3 12:52:58 CDT 2007

Stefan van der Walt wrote:
>> The current behavior is consistent and well
>>> defined:
>>> a[x] == a[int(x)]

This is all possible because of PEP 357:


However, when I read this from the PEP:

It is not possible to use the nb_int (and __int__ special method)
for this purpose because that method is used to *coerce* objects
to integers.  It would be inappropriate to allow every object that
can be coerced to an integer to be used as an integer everywhere
Python expects a true integer.  For example, if __int__ were used
to convert an object to an integer in slicing, then float objects
would be allowed in slicing and x[3.2:5.8] would not raise an error
as it should.

It seems pretty clear that only integer types were intended to by used 
as indexes. Does that make this a bug? I'll defer that to others more in 
the know than I.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list