ENH: Add equal_nan keyword argument to array_equal#16128
ENH: Add equal_nan keyword argument to array_equal#16128seberg merged 9 commits intonumpy:masterfrom
Conversation
Match the corresponding kwarg and behavior from related functions like allclose.
seberg
left a comment
There was a problem hiding this comment.
Looks good to me, could add a test for 0-D arrays containing NaN, as well as a test with a non-float type just to make a point.
rossbar
left a comment
There was a problem hiding this comment.
Thanks for taking a look @seberg - excellent suggestions as always!
I have a question about one of your suggestions:
as well as a test with a non-float type just to make a point.
I'm not sure exactly what you have in mind here. Perhaps a test with integer arrays (without nans) to show that the result is insensitive to the equal_nan kwarg? Something like:
>>> a = np.array([1, 2, 3], dtype=int)
>>> assert_(np.array_equal(a, a, equal_nan=False))
>>> assert_(np.array_equal(a, a, equal_nan=True))LMK if this is what you had in mind or if I'm missing the point :)
|
Yeah, was just thinking about such a test. A test with 2D arrays (maybe both False and True) may be good. That probably would have found the |
* 0D array of nan * 2D array with nan * integer array
| Input arrays. | ||
| equal_nan : bool | ||
| Whether to compare NaN's as equal. | ||
|
|
There was a problem hiding this comment.
Sorry, bad case of not-careful enough first review. This should have a .. versionadded:: 1.19.0 tag.
There was a problem hiding this comment.
Yup, forgot that myself. Does it need a release note as well?
|
Good idea - I've added tests for
|
* Add explanation and code example to docstring detailing how complex values are handled when equal_nan=True. * Add a test as well.
|
The discussion in #15959 is also relevant here. |
|
Thanks Ross! |
|
Nice, thanks @rossbar ! |
Following up on a suggestion by @charris in #9229 . Adds an
equal_nankwarg that toggles whether NaN's are considered equivalent when compared (default is False, which is the current behavior). This kwarg is consistent with that of related functions likeiscloseandallclose.This would close at least part of #9229, though there is other discussion in that issue about
np.testing.assert_array_equal.