diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2014-04-22 18:31:32 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2014-04-22 18:31:32 -0600 |
commit | d0b3f8f4213ee2d285be7d410a0cd7a1a601a7bd (patch) | |
tree | 91cba85428a9a9f7cdaae5971569d314944ec92d | |
parent | dd192e6ce7a99d1c24861d2875af18fced072ac9 (diff) | |
parent | ff459fd2dc3641486b35c672e0d48855669a13a5 (diff) | |
download | python-numpy-d0b3f8f4213ee2d285be7d410a0cd7a1a601a7bd.tar.gz python-numpy-d0b3f8f4213ee2d285be7d410a0cd7a1a601a7bd.tar.bz2 python-numpy-d0b3f8f4213ee2d285be7d410a0cd7a1a601a7bd.zip |
Merge pull request #4628 from mhvk/nanfunctions-copyto-call
BUG: incorrect argument order to _copyto in in np.nanmax, np.nanmin
-rw-r--r-- | numpy/lib/nanfunctions.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_nanfunctions.py | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index 5766084ab..badba32da 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -228,7 +228,7 @@ def nanmin(a, axis=None, out=None, keepdims=False): # Check for all-NaN axis mask = np.all(mask, axis=axis, keepdims=keepdims) if np.any(mask): - res = _copyto(res, mask, np.nan) + res = _copyto(res, np.nan, mask) warnings.warn("All-NaN axis encountered", RuntimeWarning) return res @@ -327,7 +327,7 @@ def nanmax(a, axis=None, out=None, keepdims=False): # Check for all-NaN axis mask = np.all(mask, axis=axis, keepdims=keepdims) if np.any(mask): - res = _copyto(res, mask, np.nan) + res = _copyto(res, np.nan, mask) warnings.warn("All-NaN axis encountered", RuntimeWarning) return res diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py index df332dfb1..f00aa0165 100644 --- a/numpy/lib/tests/test_nanfunctions.py +++ b/numpy/lib/tests/test_nanfunctions.py @@ -114,6 +114,31 @@ class TestNanFunctions_MinMax(TestCase): assert_(res.shape == (3, 1)) res = f(mat) assert_(np.isscalar(res)) + # check that rows of nan are dealt with for subclasses (#4628) + mat[1] = np.nan + for f in self.nanfuncs: + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + res = f(mat, axis=0) + assert_(isinstance(res, np.matrix)) + assert_(not np.any(np.isnan(res))) + assert_(len(w) == 0) + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + res = f(mat, axis=1) + assert_(isinstance(res, np.matrix)) + assert_(np.isnan(res[1, 0]) and not np.isnan(res[0, 0]) + and not np.isnan(res[2, 0])) + assert_(len(w) == 1, 'no warning raised') + assert_(issubclass(w[0].category, RuntimeWarning)) + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + res = f(mat) + assert_(np.isscalar(res)) + assert_(res != np.nan) + assert_(len(w) == 0) class TestNanFunctions_ArgminArgmax(TestCase): |