summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py10
-rw-r--r--numpy/ma/tests/test_core.py13
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):