-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
assert_equal gives KeyError: 0 for some Python objects. #5285
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
that type pretends to be a sequence while its a mapping, a recent optimization in discover_dimension causes the issue. |
Interesting; thanks for the pointer to |
#5063 is possibly related to this. |
yes its a related issue, though the fix is not the same (probably need to either revert or special case list/tuple), this object even has a len. I was trusting the testsuite that does cover the keyerror exception, but not in this way :( |
Numpy's assert_equal is only documented to work on arrays and built-in
|
Modifying the code to not inherit and adding a Happy to look into it, but it seems to me that it is probably fixed and the old reproducer doesn't work anymore. |
Thanks, @seberg. Agreed that it doesn't make sense to keep this open. I'd still like to understand the combination of factors that led to this, but I think if anything that belongs in a Traits issue rather than here. |
Well, the old numpy code had three different paths to walk the nested sequences (dimension discovery, dtype discovery, and filling the array) it is/may be confronted to in The new code uses |
In NumPy 1.9,
numpy.testing.assert_equal
can raise aKeyError
in some cases. An example is below. It's not as minimal as I would like: I was unable to easily remove the dependence on the Traits library.The above code fails for me under NumPy 1.9 (but not NumPy 1.8), with the following output:
I have no idea why the
array
constructor would be trying to access item0
of this object, but I can imagine that there might be valid reasons for doing so. If so, it might be useful to turn theexcept ValueError
for theuse_complex
section of theassert_equal
code intoexcept (KeyError, ValueError)
. (Code here).The text was updated successfully, but these errors were encountered: