[Numpy-discussion] changing ValueError to KeyError for bad field access
Phil Hodge
hodge at stsci.edu
Fri Jun 12 14:06:44 EDT 2015
On 06/12/2015 01:46 PM, Allan Haldane wrote:
> I think it would be very nice to make access to invalid fields of a
> structured array give a KeyError instead of a ValueError. Like:
>
> >>> a = np.ones(3, dtype=[('a', 'f4'), ('b', 'f4')])
> >>> a['c']
> KeyError: 'c'
This will break code, but it should do so in a way that's visible.
KeyError does seem like a more appropriate exception to me.
Phil
More information about the NumPy-Discussion
mailing list