summaryrefslogtreecommitdiff
path: root/numpy/oldnumeric/ma.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-13 11:17:54 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-13 11:17:54 -0600
commit54ca3f28ada715a0c84686f74f3b5a7ba4aa2c95 (patch)
tree7ea7a1632467f8d6e2917b4982809e02facf2d79 /numpy/oldnumeric/ma.py
parent688bc60658b391524c6b641e0a5e5ecd73322d02 (diff)
downloadnumpy-54ca3f28ada715a0c84686f74f3b5a7ba4aa2c95.tar.gz
2to3: Apply nonzero fixer.
In Python 3 the `__nonzero__` class method is replaced by `__bool__`. This only affects the MaskedArray class in numpy/oldnumeric/ma.py file and the simplest solution is to provide both methods. I have my doubts that the fixed up Python 3 version was correct or even tested, but I think the current solution should work for as long as oldnumeric stays in numpy. Closes #3073.
Diffstat (limited to 'numpy/oldnumeric/ma.py')
-rw-r--r--numpy/oldnumeric/ma.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py
index cdec74cab..12ca26c3d 100644
--- a/numpy/oldnumeric/ma.py
+++ b/numpy/oldnumeric/ma.py
@@ -865,6 +865,18 @@ array(data = %(data)s,
return bool(m is not nomask and m.any()
or d is not nomask and d.any())
+ def __bool__(self):
+ """returns true if any element is non-zero or masked
+
+ """
+ # XXX: This changes bool conversion logic from MA.
+ # XXX: In MA bool(a) == len(a) != 0, but in numpy
+ # XXX: scalars do not have len
+ m = self._mask
+ d = self._data
+ return bool(m is not nomask and m.any()
+ or d is not nomask and d.any())
+
def __len__ (self):
"""Return length of first dimension. This is weird but Python's
slicing behavior depends on it."""
@@ -2134,10 +2146,13 @@ def asarray(data, dtype=None):
# XXX: I is better to to change the masked_*_operation adaptors
# XXX: to wrap ndarray methods directly to create ma.array methods.
from types import MethodType
+
def _m(f):
return MethodType(f, None, array)
+
def not_implemented(*args, **kwds):
raise NotImplementedError("not yet implemented for numpy.ma arrays")
+
array.all = _m(alltrue)
array.any = _m(sometrue)
array.argmax = _m(argmax)