Skip to content

Unable to test equality of structured dtypes with no fields #13438

@mcara

Description

@mcara

If a structure type has no fields, equality throws

>>> a = np.zeros(10, dtype=[])
>>> a == a
ValueError: No fields found.

Original report:

Test for equality of empty masked arrays raises an exception.

Reproducing code example:

In [1]: import sys, numpy; print(numpy.__version__, sys.version)
1.16.3 3.6.1 (default, May 18 2017, 16:32:13) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]

In [2]: a = numpy.ma.masked_array([], dtype=[], masked=False)  # or masked=True

In [3]: a == None

Error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-991e7ea0a64c> in <module>
----> 1 a == None

~/.../lib/python3.6/site-packages/numpy/ma/core.py in __eq__(self, other)
   4043         and other considered equal only if both were fully masked.
   4044         """
-> 4045         return self._comparison(other, operator.eq)
   4046 
   4047     def __ne__(self, other):

~/.../lib/python3.6/site-packages/numpy/ma/core.py in _comparison(self, other, compare)
   3996             # Now take care of the mask; the merged mask should have an item
   3997             # masked if all fields were masked (in one and/or other).
-> 3998             mask = (mask == np.ones((), mask.dtype))
   3999 
   4000         else:

ValueError: No fields found.

Numpy/Python version information:

1.16.3 3.6.1 (default, May 18 2017, 16:32:13)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]

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