-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
accessing undefined field raises incorrect Exception #7641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
IIRC, it was a deliberate change. Do you mean |
I had a quick look at the recent release notes, but I could not find this change documented there. I'm using Python 2.7 |
Are you sure? I just checked out 1.8.0 and it gives ValueError. 1.8.3 and 1.9.3 also give ValueError. I made a couple PRs starting in 1.10 which modified a lot of this code, but I made sure to leave it as ValueError to preserve compatibility. As you can see in #5636, for example, I wanted to change it to KeyError, however I held back because of backward compatibility. There are a number of unit tests that explicitly check for ValueError. |
Interesting. Perhaps there is a bug on our end, that only manifests with the older version 1.8. |
Curious. What does |
On numpy 1.11.0, the following code raises ValueError as expected, but with numpy 1.8.2 it raises IndexError:
yields 1.8.2 $ python --version $ cat /etc/lsb-release |
Oh OK, that makes sense. What actually changed behavior is indexing a "structured scalar" rather than an array (very subtle, I know!). Indeed, in #5947 I changed it so structured scalars behave like structured arrays, so they give the same errors:
I didn't think to put the change in the release notes. @charris is it worth putting a belated note in the 1.11 notes? |
I think we can close this issue. That the exception is not ideal is also mentioned in gh-8519. |
In numpy 1.11.0, trying to access an undefined field of a structured array raises ValueError, rather than IndexError as in version 1.8
a = np.empty(1,dtype=[('f','u4')])
a['g']
yields
ValueError Traceback (most recent call last)
in ()
----> 1 a['g']
ValueError: no field of name g
Is that a feature? In any case, shouldn't it raise lookup error instead.
The text was updated successfully, but these errors were encountered: