<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1688" rel="nofollow">http://projects.scipy.org/numpy/ticket/1688</a> on 2010-11-29 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gerritholl/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gerritholl">@gerritholl</a>, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pierregm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pierregm">@pierregm</a>.</em></p>
<p dir="auto">When a MaskedArray's data are a record array,, string representation fails with a ValueError as the mask does not contain the mapping of field names that the data does.</p>
<p dir="auto">It appears the records are not carried on to the mask.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; Z = np.empty((5,), dtype=[('A', np.float32), ('B', np.uint32)])
&gt;&gt;&gt; M = np.ma.masked_where(np.array([True, False, True, False, True]), Z)
&gt;&gt;&gt; print M
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/storage4/home/gerrit/.local/lib/python2.6/site-packages/numpy/ma/core.py&quot;, line 3558, in __str__
    _recursive_printoption(res, m, f)
  File &quot;/storage4/home/gerrit/.local/lib/python2.6/site-packages/numpy/ma/core.py&quot;, line 2292, in _recursive_printoption
    (curdata, curmask) = (result[name], mask[name])
ValueError: field named A not found.
&gt;&gt;&gt; print np.version.version
2.0.0.dev-12d0200"><pre class="notranslate"><code class="notranslate">$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import numpy as np
&gt;&gt;&gt; Z = np.empty((5,), dtype=[('A', np.float32), ('B', np.uint32)])
&gt;&gt;&gt; M = np.ma.masked_where(np.array([True, False, True, False, True]), Z)
&gt;&gt;&gt; print M
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/storage4/home/gerrit/.local/lib/python2.6/site-packages/numpy/ma/core.py", line 3558, in __str__
    _recursive_printoption(res, m, f)
  File "/storage4/home/gerrit/.local/lib/python2.6/site-packages/numpy/ma/core.py", line 2292, in _recursive_printoption
    (curdata, curmask) = (result[name], mask[name])
ValueError: field named A not found.
&gt;&gt;&gt; print np.version.version
2.0.0.dev-12d0200
</code></pre></div>
<p dir="auto">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 <code class="notranslate">ValueError: field names A not found</code>, as illustrated below.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; R = numpy.empty(10, dtype=[(&quot;A&quot;, &quot;&lt;f2&quot;), (&quot;B&quot;, &quot;&lt;f4&quot;)])
&gt;&gt;&gt; Rm = numpy.ma.masked_where(R[&quot;A&quot;]&lt;0.1, R)
&gt;&gt;&gt; Rm[&quot;A&quot;]
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py&quot;, line 3014, in __getitem__
    dout._mask = _mask[indx]
ValueError: field named A not found.
&gt;&gt;&gt; print(Rm)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py&quot;, line 3583, in __str__
    _recursive_printoption(res, m, f)
  File &quot;/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py&quot;, line 2294, in _recursive_printoption
    (curdata, curmask) = (result[name], mask[name])
ValueError: field named A not found.
&gt;&gt;&gt; print(numpy.version.version)
1.8.0.dev-b8bfcd0
&gt;&gt;&gt; print(numpy.version.git_revision)
b8bfcd02a2f246a9c23675e1650c3d316d733306"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; R = numpy.empty(10, dtype=[("A", "&lt;f2"), ("B", "&lt;f4")])
&gt;&gt;&gt; Rm = numpy.ma.masked_where(R["A"]&lt;0.1, R)
&gt;&gt;&gt; Rm["A"]
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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.
&gt;&gt;&gt; print(Rm)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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.
&gt;&gt;&gt; print(numpy.version.version)
1.8.0.dev-b8bfcd0
&gt;&gt;&gt; print(numpy.version.git_revision)
b8bfcd02a2f246a9c23675e1650c3d316d733306
</code></pre></div>
<p dir="auto">I tested it with the stable version <code class="notranslate">1.6.2</code> and the bleeding-edge version obtained directly from <code class="notranslate">git</code>.<br>
It also fails in earlier stable versions (tested with 1.6.2).</p>
<p dir="auto">Note: if I instead create directly a masked array with <code class="notranslate">numpy.ma.empty</code>, I get a <em>different</em> error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; R2 = numpy.ma.empty(10, dtype=[(&quot;A&quot;, &quot;&lt;f2&quot;), (&quot;B&quot;, &quot;&lt;f4&quot;)])
&gt;&gt;&gt; Rm2 = numpy.ma.masked_where(R2[&quot;A&quot;]&lt;0.1, R2)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py&quot;, line 1810, in masked_where
    cond = mask_or(cond, a._mask)
  File &quot;/local/gerrit/python3.2-bleed/lib/python3.2/site-packages/numpy/ma/core.py&quot;, line 1627, in mask_or
    raise ValueError(&quot;Incompatible dtypes '%s'&lt;&gt;'%s'&quot; % (dtype1, dtype2))
ValueError: Incompatible dtypes 'bool'&lt;&gt;'[('A', '?'), ('B', '?')]"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; R2 = numpy.ma.empty(10, dtype=[("A", "&lt;f2"), ("B", "&lt;f4")])
&gt;&gt;&gt; Rm2 = numpy.ma.masked_where(R2["A"]&lt;0.1, R2)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  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'&lt;&gt;'%s'" % (dtype1, dtype2))
ValueError: Incompatible dtypes 'bool'&lt;&gt;'[('A', '?'), ('B', '?')]
</code></pre></div>