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
ENH: Add strict parameter to assert_array_equal. Fixes #9542 #21595
ENH: Add strict parameter to assert_array_equal. Fixes #9542 #21595
Conversation
Not sure why those tests are failing - it's picked up the change to the tests but not to numpy.testing. |
No, it is picking up things just fine the problem is that |
Ok, could I add |
Not sure what to do about these test fails. Can we rerun the pipeline when there is a network issue? |
Needs a release note in |
I've often wanted a strict version of the array equality test functions. I would like it to be even stricter than the change proposed here, and only pass if the shape and data types match exactly. So if |
This sounds like a good idea to me. It makes sense that a "strict" check would also enforce the types. I was also wondering if we should add the same parameter to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add the new function parameters to the utils.pyi stub file?
Make new arguments keyword-only Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Does it count as a |
The mailing list discussion is here. I think this is the best available solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I concur with Matti. I did not remember that it also makes the dtype strict.
This seems like a good idea and I suspect it makes using strict=True
useful in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few nitpicky inline comments. The more significant (but still not major) issue that should be fixed is that when the shapes of two arrays match but the dtypes do not, the error message is not correct. E.g.
In [19]: assert_array_equal(np.eye(2), np.eye(2, dtype=np.float32), strict=True)
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<...snip...>
AssertionError:
Arrays are not equal
(shapes (2, 2), (2, 2) mismatch)
x: array([[1., 0.],
[0., 1.]])
y: array([[1., 0.],
[0., 1.]], dtype=float32)
The error message says (shapes (2, 2), (2, 2) mismatch)
but the shapes do match. In this case, the error message should report that the dtypes do not match.
Thanks @jontwo, the updates look good. I'll merge in a couple days if no one does it before then. |
It's useful to have
assert_array_equal
broadcast a scalar to match every value in an array, but it would be nice to be able to turn this behaviour off. Sometimes you need to have an exact match.