From 83fb19e7f37502df72d4c4865138f7d84de7c517 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Sun, 13 Oct 2013 22:39:40 -0400 Subject: [PATCH] Ensure masked arrays are treated correctly for isclose(..,..,equal_nan=True) --- numpy/core/numeric.py | 3 ++- numpy/core/tests/test_numeric.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 1aa59ce58880..53254ec6a4f5 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2216,7 +2216,8 @@ def within_tol(x, y, atol, rtol): cond[~finite] = (x[~finite] == y[~finite]) if equal_nan: # Make NaN == NaN - cond[isnan(x) & isnan(y)] = True + both_nan = isnan(x) & isnan(y) + cond[both_nan] = both_nan[both_nan] return cond def array_equal(a1, a2): diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 8dc2ebd7160b..913599e09408 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -1454,6 +1454,12 @@ def test_masked_arrays(self): # Ensure that the mask isn't modified... assert_array_equal([True, True, False], y.mask) + x = np.ma.masked_where([True, True, False], [nan, nan, nan]) + y = isclose(x, x, equal_nan=True) + assert_(type(x) is type(y)) + # Ensure that the mask isn't modified... + assert_array_equal([True, True, False], y.mask) + def test_scalar_return(self): assert_(isscalar(isclose(1, 1)))