-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Labels
Description
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