-
-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Unable to test equality of structured dtypes with no fields #13438
Copy link
Copy link
Closed
Description
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 == NoneError 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)]
Reactions are currently unavailable