diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-14 07:33:29 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-14 07:33:29 -0700 |
commit | 61c5ac6758d05da6cf49b7247eca850d9db83a7a (patch) | |
tree | 536928e9a905c4f75165b69d526e4d0a591c9bf6 /numpy/oldnumeric/ma.py | |
parent | ff464ef985cb4d3bca82cc0e7867e02ca47482dc (diff) | |
parent | 54ca3f28ada715a0c84686f74f3b5a7ba4aa2c95 (diff) | |
download | numpy-61c5ac6758d05da6cf49b7247eca850d9db83a7a.tar.gz |
Merge pull request #3241 from charris/2to3-apply-nonzero-fixer
2to3: Apply nonzero fixer.
Diffstat (limited to 'numpy/oldnumeric/ma.py')
-rw-r--r-- | numpy/oldnumeric/ma.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py index 05a4480af..3b861709e 100644 --- a/numpy/oldnumeric/ma.py +++ b/numpy/oldnumeric/ma.py @@ -873,6 +873,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.""" @@ -2142,10 +2154,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) |