[Numpy-discussion] better error message possible?
Travis Vaught
travis at vaught.net
Thu Jun 7 11:02:31 EDT 2012
On Jun 7, 2012, at 4:32 AM, Paul Anton Letnes wrote:
>
> On 7. juni 2012, at 10:30, Thouis (Ray) Jones wrote:
>
>> I've opened a PR at https://github.com/numpy/numpy/pull/296 for discussion.
>>
>> A typical result
>>
>>>>> np.zeros((3,3))[[1,2,3]]
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> IndexError: index 3 is out of bounds for axis 0: [-3,3)
>>
>> Ray Jones
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> I would prefer:
> IndexError: index 3 is out of bounds for axis 0: [-3,2]
> as I find the 3) notation a bit weird - after all, indices are not floats, so 2.999 or 2.3 doesn't make sense as an index.
Actually, with slicing, you can attempt indexing using floats (as referred to here: http://stackoverflow.com/questions/8514547/why-ndarray-allow-floating-point-index), so I disagree with the integer notation [-3,2]
I actually prefer the subsequent suggestion of reporting the shape, since that's what I always check when debugging index errors anyway -- having it in the error message would save me a ton of time.
>
> An alternative is to not refer to negative indices and say
> IndexError: index 3 is out of bounds for axis 0, shape was: (3,)
> (print more axes when the number of axes is higher.)
>
> BTW, I'm really glad someone is taking an interest in these error messages, it's a great idea!
>
… an enthusiastic +1!
> Paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120607/c8336a4c/attachment.html>
More information about the NumPy-Discussion
mailing list