[Numpy-discussion] nanmin(<masked array>) fails with 'TypeError: cannot reduce a scalar'. Numpy 1.6.0 regression?

Charles R Harris charlesr.harris at gmail.com
Wed Jul 27 15:20:07 EDT 2011


On Wed, Jul 27, 2011 at 6:58 AM, Charles R Harris <charlesr.harris at gmail.com
> wrote:

>
>
> On Wed, Jul 27, 2011 at 2:49 AM, Mark Dickinson <mdickinson at enthought.com>wrote:
>
>> In NumPy 1.6.0, I get the following behaviour:
>>
>>
>> Python 2.7.2 |EPD 7.1-1 (32-bit)| (default, Jul  3 2011, 15:40:35)
>> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>> Type "packages", "demo" or "enthought" for more information.
>> >>> import numpy
>> >>> numpy.nanmin(numpy.ma.masked_array([1,2,3,4]))
>> Traceback (most recent call last):
>>  File "<stdin>", line 1, in <module>
>>  File
>> "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/numpy/lib/function_base.py",
>> line 1507, in nanmin
>>    return np.fmin.reduce(a.flat)
>> TypeError: cannot reduce on a scalar
>> >>> numpy.__version__
>> '1.6.0'
>>
>>
>> In NumPy version 1.5.1:
>>
>> Python 2.7.2 |EPD 7.1-1 (32-bit)| (default, Jul  3 2011, 15:40:35)
>> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>> Type "packages", "demo" or "enthought" for more information.
>> >>> import numpy
>> >>> numpy.nanmin(numpy.ma.masked_array([1,2,3,4]))
>> 1
>> >>> numpy.__version__
>> '1.5.1'
>>
>>
>> Was this change intentional?
>>
>>
> No, it comes from this
>
> In [2]: a = numpy.ma.masked_array([1,2,3,4])
>
> In [3]: array(a.flat)
> Out[3]: array(<numpy.ma.core.MaskedIterator object at 0x1fd1f90>,
> dtype='object')
>
> i.e., the a.flat iterator is turned into an object array with one element.
> I'm not sure what the correct fix for this would be. Please open a ticket.
>
>
In fact, array no longer recognizes iterators, but a.flat works, so I assume
the __array__ attribute of the array iterator is at work. I think nanmin
needs to be fixed, because it used a.flat for speed, but it looks like
something closer to 'asflat' is needed. In addition, array probably needs to
be fixed to accept iterators, I think it used to.

How did nanmin interact with the mask of masked arrays in earlier versions?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110727/f31b63a0/attachment.html>


More information about the NumPy-Discussion mailing list