summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-04-11 22:33:27 +0000
committerpierregm <pierregm@localhost>2009-04-11 22:33:27 +0000
commitae58b00fee1839ba7e21ddfd7ebbf87f732caeb5 (patch)
treeacca2f4c8b9cce253ac2afeb385976663c7838ad
parent5e0e9559b9ec679b6902129bef46c84707abf865 (diff)
downloadnumpy-ae58b00fee1839ba7e21ddfd7ebbf87f732caeb5.tar.gz
_arraymethod : fallback when a method is called as MaskedArray.method
-rw-r--r--numpy/ma/core.py13
-rw-r--r--numpy/ma/tests/test_core.py12
2 files changed, 21 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 29dc82815..14ba3ca8f 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -2124,11 +2124,16 @@ class _arraymethod(object):
#
def __call__(self, *args, **params):
methodname = self.__name__
- data = self.obj._data
- mask = self.obj._mask
- cls = type(self.obj)
+ instance = self.obj
+ # Fallback : if the instance has not been initialized, use the first arg
+ if instance is None:
+ args = list(args)
+ instance = args.pop(0)
+ data = instance._data
+ mask = instance._mask
+ cls = type(instance)
result = getattr(data, methodname)(*args, **params).view(cls)
- result._update_from(self.obj)
+ result._update_from(instance)
if result.ndim:
if not self._onmask:
result.__setmask__(mask)
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 1e127abff..3ac4fce9e 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -2272,6 +2272,18 @@ class TestMaskedArrayMethods(TestCase):
assert_equal(test, a)
assert_equal(test.data, a.data)
+
+ def test_arraymethod(self):
+ "Test a _arraymethod w/ n argument"
+ marray = masked_array([[1, 2, 3, 4, 5]], mask=[0, 0, 1, 0, 0])
+ control = masked_array([[1], [2], [3], [4], [5]],
+ mask=[0, 0, 1, 0, 0])
+ assert_equal(marray.T, control)
+ assert_equal(marray.transpose(), control)
+ #
+ assert_equal(MaskedArray.cumsum(marray.T, 0), control.cumsum(0))
+
+
#------------------------------------------------------------------------------