From b0124491e6b5e2edc96c2af92f4ec8727319f252 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 13 Apr 2017 14:14:13 +0100 Subject: DEP: Deprecate single-argument np.ma.m(in|ax)imum This shorthand is just inconsistent with `np.maximum`, and just makes the distinction between `np.ma.max` and `np.ma.maximum` even more confusing. Also adds names to these objects, since 1) they're there in core, and 2) they make the warning message more helpful. --- numpy/ma/core.py | 14 ++++++++++---- numpy/ma/tests/test_core.py | 10 +++++----- numpy/ma/tests/test_deprecations.py | 8 ++++++++ numpy/ma/tests/test_old_ma.py | 8 ++++---- 4 files changed, 27 insertions(+), 13 deletions(-) (limited to 'numpy/ma') diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 8861a3464..c3f80ea27 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -5673,10 +5673,7 @@ class MaskedArray(ndarray): "`mini` is deprecated; use the `min` method or " "`np.ma.minimum.reduce instead.", DeprecationWarning, stacklevel=2) - if axis is None: - return minimum(self) - else: - return minimum.reduce(self, axis) + return minimum.reduce(self, axis) def max(self, axis=None, out=None, fill_value=None, keepdims=np._NoValue): """ @@ -6371,9 +6368,18 @@ class _extrema_operation(object): """ + @property + def __name__(self): + return self.ufunc.__name__ + def __call__(self, a, b=None): "Executes the call behavior." if b is None: + # 2016-04-13, 1.13.0 + warnings.warn( + "Single-argument form of np.ma.{0} is deprecated. Use " + "np.ma.{0}.reduce instead.".format(self.__name__), + DeprecationWarning, stacklevel=2) return self.reduce(a) return where(self.compare(a, b), a, b) diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index f807fc8ae..f20c9ba52 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1049,8 +1049,8 @@ class TestMaskedArrayArithmetic(TestCase): xr = np.ravel(x) xmr = ravel(xm) # following are true because of careful selection of data - assert_equal(max(xr), maximum(xmr)) - assert_equal(min(xr), minimum(xmr)) + assert_equal(max(xr), maximum.reduce(xmr)) + assert_equal(min(xr), minimum.reduce(xmr)) assert_equal(minimum([1, 2, 3], [4, 0, 9]), [1, 0, 3]) assert_equal(maximum([1, 2, 3], [4, 0, 9]), [4, 2, 9]) @@ -1060,12 +1060,12 @@ class TestMaskedArrayArithmetic(TestCase): y[0] = masked assert_equal(minimum(x, y), where(less(x, y), x, y)) assert_equal(maximum(x, y), where(greater(x, y), x, y)) - assert_(minimum(x) == 0) - assert_(maximum(x) == 4) + assert_(minimum.reduce(x) == 0) + assert_(maximum.reduce(x) == 4) x = arange(4).reshape(2, 2) x[-1, -1] = masked - assert_equal(maximum(x), 2) + assert_equal(maximum.reduce(x), 2) def test_minimummaximum_func(self): a = np.ones((2, 2)) diff --git a/numpy/ma/tests/test_deprecations.py b/numpy/ma/tests/test_deprecations.py index d66980031..6b3c30e04 100644 --- a/numpy/ma/tests/test_deprecations.py +++ b/numpy/ma/tests/test_deprecations.py @@ -37,5 +37,13 @@ class TestArgsort(TestCase): return self._test_base(np.ma.MaskedArray.argsort, np.ma.MaskedArray) +class TestMinimumMaximum(TestCase): + def test_minimum(self): + assert_warns(DeprecationWarning, np.ma.minimum, np.ma.array([1, 2])) + + def test_maximum(self): + assert_warns(DeprecationWarning, np.ma.maximum, np.ma.array([1, 2])) + + if __name__ == "__main__": run_module_suite() diff --git a/numpy/ma/tests/test_old_ma.py b/numpy/ma/tests/test_old_ma.py index 2ea53683d..51fa6ac36 100644 --- a/numpy/ma/tests/test_old_ma.py +++ b/numpy/ma/tests/test_old_ma.py @@ -182,8 +182,8 @@ class TestMa(TestCase): xmr = ravel(xm) # true because of careful selection of data - self.assertTrue(eq(max(xr), maximum(xmr))) - self.assertTrue(eq(min(xr), minimum(xmr))) + self.assertTrue(eq(max(xr), maximum.reduce(xmr))) + self.assertTrue(eq(min(xr), minimum.reduce(xmr))) def test_testAddSumProd(self): # Test add, sum, product. @@ -444,8 +444,8 @@ class TestMa(TestCase): y[0] = masked assert_(eq(minimum(x, y), where(less(x, y), x, y))) assert_(eq(maximum(x, y), where(greater(x, y), x, y))) - assert_(minimum(x) == 0) - assert_(maximum(x) == 4) + assert_(minimum.reduce(x) == 0) + assert_(maximum.reduce(x) == 4) def test_testTakeTransposeInnerOuter(self): # Test of take, transpose, inner, outer products -- cgit v1.2.1