nanmin(<masked array>) fails with 'TypeError: cannot reduce a scalar'. Numpy 1.6.0 regression?
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",
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. 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? -- Mark
On Wed, Jul 27, 2011 at 2:49 AM, Mark Dickinson <mdickinson@enthought.com>wrote:
In NumPy 1.6.0, I get the following behaviour:
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",
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. 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. Chuck
On Wed, Jul 27, 2011 at 6:58 AM, Charles R Harris <charlesr.harris@gmail.com
wrote:
On Wed, Jul 27, 2011 at 2:49 AM, Mark Dickinson <mdickinson@enthought.com>wrote:
In NumPy 1.6.0, I get the following behaviour:
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",
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. 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
On Wed, Jul 27, 2011 at 2:20 PM, Charles R Harris <charlesr.harris@gmail.com
wrote:
On Wed, Jul 27, 2011 at 6:58 AM, Charles R Harris < charlesr.harris@gmail.com> wrote:
On Wed, Jul 27, 2011 at 2:49 AM, Mark Dickinson <mdickinson@enthought.com
wrote:
In NumPy 1.6.0, I get the following behaviour:
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",
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. 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.
I'd guess this slipped through with something I changed when I was in the array construction part of the system, because the test suite doesn't exercise this. Any NumPy behavior we want preserved needs tests! -Mark
How did nanmin interact with the mask of masked arrays in earlier versions?
Chuck
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (3)
-
Charles R Harris
-
Mark Dickinson
-
Mark Wiebe