-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Accessing fields for a masked structured array fails with ValueError #2972
Copy link
Copy link
Closed
Labels
Description
I'm trying to create a mask for a structured array. When I try to access a field from the array or simply represent it, numpy throws a ValueError: field names A not found, as illustrated below.
>>> R = numpy.empty(10, dtype=[("A", "<f2"), ("B", "<f4")])
>>> Rm = numpy.ma.masked_where(R["A"]<0.1, R)
>>> Rm["A"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py", line 3014, in __getitem__
dout._mask = _mask[indx]
ValueError: field named A not found.
>>> print(Rm)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py", line 3583, in __str__
_recursive_printoption(res, m, f)
File "/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py", line 2294, in _recursive_printoption
(curdata, curmask) = (result[name], mask[name])
ValueError: field named A not found.
>>> print(numpy.version.version)
1.8.0.dev-b8bfcd0
>>> print(numpy.version.git_revision)
b8bfcd02a2f246a9c23675e1650c3d316d733306
I tested it with the stable version 1.6.2 and the bleeding-edge version obtained directly from git.
It also fails in earlier stable versions (tested with 1.6.2).
Note: if I instead create directly a masked array with numpy.ma.empty, I get a different error:
>>> R2 = numpy.ma.empty(10, dtype=[("A", "<f2"), ("B", "<f4")])
>>> Rm2 = numpy.ma.masked_where(R2["A"]<0.1, R2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py", line 1810, in masked_where
cond = mask_or(cond, a._mask)
File "/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py", line 1627, in mask_or
raise ValueError("Incompatible dtypes '%s'<>'%s'" % (dtype1, dtype2))
ValueError: Incompatible dtypes 'bool'<>'[('A', '?'), ('B', '?')]
Reactions are currently unavailable