Skip to content

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

Closed

Description

@mhvk

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions