Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: masked structured arrays cannot be compared to their unmasked counterparts #24554

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

Closed
mhvk opened this issue Aug 26, 2023 · 0 comments · Fixed by #24556
Closed

BUG: masked structured arrays cannot be compared to their unmasked counterparts #24554

mhvk opened this issue Aug 26, 2023 · 0 comments · Fixed by #24556

Comments

@mhvk
Copy link
Contributor

mhvk commented Aug 26, 2023

Describe the issue:

A structured masked array can be compared to another, but not to an unstructured one, since then the absence of a mask is not treated correctly (I fear in code I wrote, very weird that this was not found earlier and not already tested!).

Reproduce the code example:

import numpy as np
a = np.array([(1., 2.), (3., 4.)], "f8,f8")
ma = np.ma.MaskedArray(a)
ma == ma
# masked_array(data=[True, True],
#              mask=[False, False],
#        fill_value=True)
ma == a
# TypeError: Cannot compare structured or void to non-void arrays.

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/ma/core.py", line 4161, in __eq__
    return self._comparison(other, operator.eq)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/numpy/ma/core.py", line 4129, in _comparison
    check = np.where(mask, compare(smask, omask), check)
                           ^^^^^^^^^^^^^^^^^^^^^
TypeError: Cannot compare structured or void to non-void arrays.

Runtime information:

1.24.2
3.11.4 (main, Jun 7 2023, 10:13:09) [GCC 12.2.0]

Context for the issue:

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants