[Numpy-discussion] changing ValueError to KeyError for bad field access

Allan Haldane allanhaldane at gmail.com
Fri Jun 12 13:46:39 EDT 2015


Hi all,

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'

A commit in my PR https://github.com/numpy/numpy/pull/5636 does this. As
discussed there, backwards compatibility is a problem but it seems like
the impact might be fairly small.

Any opinions?

Allan



More information about the NumPy-Discussion mailing list