diff options
author | Eric Firing <efiring@hawaii.edu> | 2013-06-15 16:47:55 -1000 |
---|---|---|
committer | Eric Firing <efiring@hawaii.edu> | 2013-06-16 09:23:17 -1000 |
commit | c2465b647adc8c7de8359b89b54c2203a0952ba5 (patch) | |
tree | a7bb30506af92513d3699b671cadba8e99896915 | |
parent | e036deb49b74fc2432066497d7c1d4bb61a74caa (diff) | |
download | numpy-c2465b647adc8c7de8359b89b54c2203a0952ba5.tar.gz |
BUG: np.ma.compress treated inputs in wrong order; closes #2495
-rw-r--r-- | numpy/ma/core.py | 10 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 13 |
2 files changed, 21 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 223f119b8..99b3e4efc 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5975,9 +5975,10 @@ class _frommethod: Name of the method to transform. """ - def __init__(self, methodname): + def __init__(self, methodname, reversed=False): self.__name__ = methodname self.__doc__ = self.getdoc() + self.reversed = reversed # def getdoc(self): "Return the doc of the function (from the doc of the method)." @@ -5989,6 +5990,11 @@ class _frommethod: return doc # def __call__(self, a, *args, **params): + if self.reversed: + args = list(args) + arr = args[0] + args[0] = a + a = arr # Get the method from the array (if possible) method_name = self.__name__ method = getattr(a, method_name, None) @@ -6005,7 +6011,7 @@ class _frommethod: all = _frommethod('all') anomalies = anom = _frommethod('anom') any = _frommethod('any') -compress = _frommethod('compress') +compress = _frommethod('compress', reversed=True) cumprod = _frommethod('cumprod') cumsum = _frommethod('cumsum') copy = _frommethod('copy') diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 263a9735a..393513eba 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -3381,6 +3381,19 @@ class TestMaskedArrayFunctions(TestCase): test = reshape(a, (2, 2)) assert_equal(test, m.reshape(2, 2)) + def test_compress(self): + # Test compress function on ndarray and masked array + # Address Github #2495. + arr = np.arange(8) + arr.shape = 4,2 + cond = np.array([True, False, True, True]) + control = arr[[0, 2, 3]] + test = np.ma.compress(cond, arr, axis=0) + assert_equal(test, control) + marr = np.ma.array(arr) + test = np.ma.compress(cond, marr, axis=0) + assert_equal(test, control) + #------------------------------------------------------------------------------ class TestMaskedFields(TestCase): |