diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2013-06-16 17:40:58 -0700 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2013-06-16 17:40:58 -0700 |
| commit | 8f547d3a42d12e8d7ac993eef37bc3088de60688 (patch) | |
| tree | f39457cd63ba80c7d599b8d08d6559199efdb4fe /numpy | |
| parent | 5e977d8358fd06b5466b146f3069a7a15d9309a0 (diff) | |
| parent | c2465b647adc8c7de8359b89b54c2203a0952ba5 (diff) | |
| download | numpy-8f547d3a42d12e8d7ac993eef37bc3088de60688.tar.gz | |
Merge pull request #3448 from efiring/ma_compress
BUG: np.ma.compress treated inputs in wrong order; closes #2495
Diffstat (limited to 'numpy')
| -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 fc086e5b7..b2e6ad91b 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5983,9 +5983,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)." @@ -5997,6 +5998,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) @@ -6013,7 +6019,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 3b25090ab..a32f6a76b 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): |
