Skip to content
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

BUG: ma.testutils.assert_equal throws AssertionError on np.nan #20017

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

iam-abbas
Copy link

@iam-abbas iam-abbas commented Oct 1, 2021

Fixes #6661, #20022. np.ma.testutils.assert_equal now defaults to np.testing.assert_equal if actual or desired are not masked

Previously

>>> import numpy as np
>>> np.testing.assert_qual(np.nan, np.nan)
>>> np.ma.testutils.assert_equal(np.nan, np.nan)
AssertionError: 
Items are not equal:
 ACTUAL: nan
 DESIRED: nan

After Fix

>>> import numpy as np
>>> np.testing.assert_qual(np.nan, np.nan)
>>> np.ma.testutils.assert_equal(np.nan, np.nan)

@iam-abbas
Copy link
Author

@charris would you mind reviewing this? Thanks!

@seberg seberg added the component: numpy.ma masked arrays label Oct 4, 2021
@iam-abbas
Copy link
Author

Waiting for this to be merged



if __name__ == "__main__":
run_module_suite()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this replace existing tests, if so please remove them from the previous locations.

@@ -108,7 +108,7 @@ def assert_equal_records(a, b):
def assert_equal(actual, desired, err_msg=''):
"""
Asserts that two items are equal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change

Suggested change

@@ -126,7 +126,8 @@ def assert_equal(actual, desired, err_msg=''):
if not (isinstance(actual, ndarray) or isinstance(desired, ndarray)):
msg = build_err_msg([actual, desired], err_msg,)
if not desired == actual:
raise AssertionError(msg)
# Handle case using testing.assert_equal
return np.testing.assert_equal(actual, desired)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem right. Why build the error message and do the check, only to defer to the base-class check? Also: What happens if the order of the arguments is reversed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Pending authors' response
Development

Successfully merging this pull request may close these issues.

Bug: ma.testutils.assert_equal on nans throws AssertionError
3 participants