<div class="gmail_quote">On Mon, Jan 16, 2012 at 8:14 AM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div><div class="h5">On Mon, Jan 16, 2012 at 8:52 AM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br><br><div class="gmail_quote"><div><div>On Mon, Jan 16, 2012 at 8:37 AM, Bruce Southey <span dir="ltr"><<a href="mailto:bsouthey@gmail.com" target="_blank">bsouthey@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<u></u>
<div bgcolor="#ffffff" text="#000000"><div><div>
On 01/14/2012 04:31 PM, Charles R Harris wrote:
</div></div><blockquote type="cite"><div><div>I've put up a pull request for a fix to ticket #1973.
Currently the fix simply propagates the maskna flag when the
*.astype method is called. A more complicated option would be to
add a maskna keyword to specify whether the output is masked or
not or propagates the type of the source, but that seems overly
complex to me.<br>
<br>
Thoughts?<br>
<br>
Chuck<br>
</div></div><pre><fieldset></fieldset>
_______________________________________________
NumPy-Discussion mailing list
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a>
</pre>
</blockquote>
Thanks for the correction and as well as the fix. While it worked
for integer and floats (not complex ones), I got an error when using
complex dtypes. This error that is also present in array creation of
complex dtypes. Is this known or a new bug?<br>
<br>
If it is new, then we need to identify what functionality should
handle np.NA but are not working.<br>
<br>
Bruce<br>
<br>
$ python<br>
Python 2.7 (r27:82500, Sep 16 2010, 18:02:00) <br>
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2<br>
Type "help", "copyright", "credits" or "license" for more
information.<br>
>>> import numpy as np<br>
>>> np.__version__ # pull request version<br>
'2.0.0.dev-88f9276'<br>
>>> np.array([1,2], dtype=np.complex)<br>
array([ 1.+0.j, 2.+0.j])<br>
>>> np.array([1,2, np.NA], dtype=np.complex)<br>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py",
line 1445, in array_repr<br>
', ', "array(")<br>
File
"/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py", line
459, in array2string<br>
separator, prefix, formatter=formatter)<br>
File
"/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py", line
263, in _array2string<br>
suppress_small),<br>
File
"/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py", line
724, in __init__<br>
self.real_format = FloatFormat(x.real, precision,
suppress_small)<br>
ValueError: Cannot construct a view of data together with the
NPY_ARRAY_MASKNA flag, the NA mask must be added later<br>
>>> ca=np.array([1,2], dtype=np.complex, maskna=True)<br>
>>> ca[1]=np.NA<br>
>>> ca<br>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py",
line 1445, in array_repr<br>
', ', "array(")<br>
File
"/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py", line
459, in array2string<br>
separator, prefix, formatter=formatter)<br>
File
"/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py", line
263, in _array2string<br>
suppress_small),<br>
File
"/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py", line
724, in __init__<br>
self.real_format = FloatFormat(x.real, precision,
suppress_small)<br>
ValueError: Cannot construct a view of data together with the
NPY_ARRAY_MASKNA flag, the NA mask must be added later<br>
>>> <br>
<br></div></blockquote></div></div><div><br>Looks like a different bug involving the *.real and *.imag views. I'll take a look.<br><br></div></div></blockquote></div></div><div><br>Looks like views of masked arrays have other problems:<br>
<br>In [13]: a = ones(3, int16, maskna=1)<br><br>In [14]: a.view(int8)<br>Out[14]: array([1, 0, 1, NA, 1, NA], dtype=int8)<br><br></div></div></blockquote><div><br></div><div>This looks like a serious bug to me, to avoid memory corruption issues it should raise an exception.</div>
<div><br></div><div>-Mark</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div><br>I'm not sure what the policy should be here. One could construct a new mask adapted to the view, raise an error when the types don't align (I think the real/imag parts should be considered aligned), or just let the view unmask the array. The last seems dangerous. Hmm...<br>
</div></div></blockquote><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div>
<br>Chuck<br></div></div><br>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br>