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

assert_tree_match and np.testing ignores array masks #1806

Open
braingram opened this issue Jul 18, 2024 · 0 comments
Open

assert_tree_match and np.testing ignores array masks #1806

braingram opened this issue Jul 18, 2024 · 0 comments

Comments

@braingram
Copy link
Contributor

While reviewing #1803 a somewhat related issue was found. See #1803 (comment) for the initial comment.

asdf._tests._helpers.assert_tree_match discards array masks during the comparison.
This is caused by 2 related issues (both covered here) and this line:

np.testing.assert_array_equal(old.__array__(), new.__array__())

The call to __array__ drops the mask:

import numpy as np
arr = np.arange(5)
m0 = np.ma.masked_array(arr, False)
a2 = m0.__array__()
print(f"{type(a2)}: {a2}")

returns

<class 'numpy.ndarray'>: [0 1 2 3 4]

So the mask never makes it to assert_array_equal. Furthermore:

import numpy as np
arr = np.arange(5)
m0 = np.ma.masked_array(arr, True)
m1 = np.ma.masked_array(arr, False)
np.testing.assert_array_equal(m0, m11)

Does not fail (as it appears assert_array_equal (and assert_equal) ignore masks.

As our test suite contains several masked arrays it seems worthwhile to:

  • update assert_tree_match to handle the masks (or remove that test function)
  • replace all uses of np.testing that might handle a masked array (I'm not sure if there's a drop-in replacement or some argument we can provide).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant