[Numpy-discussion] Fix for ticket #1973
Mark Wiebe
mwwiebe at gmail.com
Tue Jan 24 19:59:22 EST 2012
On Mon, Jan 16, 2012 at 8:14 AM, Charles R Harris <charlesr.harris at gmail.com
> wrote:
>
>
> On Mon, Jan 16, 2012 at 8:52 AM, Charles R Harris <
> charlesr.harris at gmail.com> wrote:
>
>>
>>
>> On Mon, Jan 16, 2012 at 8:37 AM, Bruce Southey <bsouthey at gmail.com>wrote:
>>
>>> **
>>> On 01/14/2012 04:31 PM, Charles R Harris wrote:
>>>
>>> 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.
>>>
>>> Thoughts?
>>>
>>> Chuck
>>>
>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing listNumPy-Discussion at scipy.orghttp://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>> 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?
>>>
>>> If it is new, then we need to identify what functionality should handle
>>> np.NA but are not working.
>>>
>>> Bruce
>>>
>>> $ python
>>> Python 2.7 (r27:82500, Sep 16 2010, 18:02:00)
>>> [GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.
>>> >>> import numpy as np
>>> >>> np.__version__ # pull request version
>>> '2.0.0.dev-88f9276'
>>> >>> np.array([1,2], dtype=np.complex)
>>> array([ 1.+0.j, 2.+0.j])
>>> >>> np.array([1,2, np.NA], dtype=np.complex)
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py", line
>>> 1445, in array_repr
>>> ', ', "array(")
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py",
>>> line 459, in array2string
>>> separator, prefix, formatter=formatter)
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py",
>>> line 263, in _array2string
>>> suppress_small),
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py",
>>> line 724, in __init__
>>> self.real_format = FloatFormat(x.real, precision, suppress_small)
>>> ValueError: Cannot construct a view of data together with the
>>> NPY_ARRAY_MASKNA flag, the NA mask must be added later
>>> >>> ca=np.array([1,2], dtype=np.complex, maskna=True)
>>> >>> ca[1]=np.NA
>>> >>> ca
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/numeric.py", line
>>> 1445, in array_repr
>>> ', ', "array(")
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py",
>>> line 459, in array2string
>>> separator, prefix, formatter=formatter)
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py",
>>> line 263, in _array2string
>>> suppress_small),
>>> File "/usr/lib64/python2.7/site-packages/numpy/core/arrayprint.py",
>>> line 724, in __init__
>>> self.real_format = FloatFormat(x.real, precision, suppress_small)
>>> ValueError: Cannot construct a view of data together with the
>>> NPY_ARRAY_MASKNA flag, the NA mask must be added later
>>> >>>
>>>
>>>
>> Looks like a different bug involving the *.real and *.imag views. I'll
>> take a look.
>>
>>
> Looks like views of masked arrays have other problems:
>
> In [13]: a = ones(3, int16, maskna=1)
>
> In [14]: a.view(int8)
> Out[14]: array([1, 0, 1, NA, 1, NA], dtype=int8)
>
>
This looks like a serious bug to me, to avoid memory corruption issues it
should raise an exception.
-Mark
>
> 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...
>
> Chuck
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120124/dbb841ef/attachment.html>
More information about the NumPy-Discussion
mailing list