Skip to content

Commit

Permalink
Merge pull request numpy#3241 from charris/2to3-apply-nonzero-fixer
Browse files Browse the repository at this point in the history
2to3: Apply nonzero fixer.
  • Loading branch information
charris committed Apr 14, 2013
2 parents ff464ef + 54ca3f2 commit 61c5ac6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions numpy/oldnumeric/ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,18 @@ def __nonzero__(self):
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."""
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/py3tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
'methodattrs',
'ne',
# 'next',
# 'nonzero',
'nonzero',
'numliterals',
'operator',
'paren',
Expand Down

0 comments on commit 61c5ac6

Please sign in to comment.