[Numpy-tickets] [NumPy] #645: maskedarray extrema operations break on non-array types
NumPy
numpy-tickets@scipy....
Mon Jan 14 12:41:18 CST 2008
#645: maskedarray extrema operations break on non-array types
---------------------+------------------------------------------------------
Reporter: bsulman | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.0.5
Component: Other | Version: none
Severity: normal | Keywords: maskedarray extrema
---------------------+------------------------------------------------------
Extrema operations in maskedarray raise an exception when used on a non-
array object. Example:
{{{
In [1]: import maskedarray as ma
In [2]: import numpy.core.ma as MA
In [3]: l=[1,2,3]
In [4]: max(l)
Out[4]: 3
In [5]: MA.maximum(l)
Out[5]: 3
In [6]: ma.max(l)
---------------------------------------------------------------------------
<type 'exceptions.AttributeError'> Traceback (most recent call
last)
/home/bsulman/<ipython console> in <module>()
/home/bsulman/lib/python/maskedarray/core.py in max(obj, axis, out)
2386 raise TypeError("Output arrays Unsupported for masked
arrays")
2387 if axis is None:
-> 2388 return maximum(obj)
2389 else:
2390 return maximum.reduce(obj, axis)
/home/bsulman/lib/python/maskedarray/core.py in __call__(self, a, b)
2307 "Executes the call behavior."
2308 if b is None:
-> 2309 return self.reduce(a)
2310 return where(self.compare(a, b), a, b)
2311 #.........
/home/bsulman/lib/python/maskedarray/core.py in reduce(self, target, axis)
2317 else:
2318 kargs = {}
-> 2319 target = target.ravel()
2320 if not (m is nomask):
2321 m = m.ravel()
<type 'exceptions.AttributeError'>: 'list' object has no attribute 'ravel'
}}}
The maskedarray version of _extrema_operation.reduce (line 2535 in
branches/maskedarray/numpy/ma/core.py) calls target.ravel() for axis=None.
(I'm using the older scipy.sandbox version of maskedarray but the line
number I gave is for the maskedarray branch version and the problem still
appears to be there.) This is a problem because doing a
{{{ from maskedarray import * }}}
will break the builtin max and min functions for non-array objects.
Probably the easiest fix is just to call array(object) in reduce?
Thanks!
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/645>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list