From 5718b3306303b4899c017641a9282714dcf8c9b8 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Sat, 19 May 2018 12:21:47 -0400 Subject: BUG,MAINT: Ensure masked elements can be tested against nan and inf. The removal of nan and inf from arrays that are compared using test routines like assert_array_equal treated the two arrays separately, which for masked arrays meant that some elements would not be removed when they should have been. This PR corrects this. --- numpy/testing/tests/test_utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 602cdf5f2..235b3750c 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -151,6 +151,17 @@ class TestArrayEqual(_GenericTest): self._test_not_equal(c, b) assert_equal(len(l), 1) + def test_masked_nan_inf(self): + # Regression test for gh-11121 + a = np.ma.MaskedArray([3., 4., 6.5], mask=[False, True, False]) + b = np.array([3., np.nan, 6.5]) + self._test_equal(a, b) + self._test_equal(b, a) + a = np.ma.MaskedArray([3., 4., 6.5], mask=[True, False, False]) + b = np.array([np.inf, 4., 6.5]) + self._test_equal(a, b) + self._test_equal(b, a) + class TestBuildErrorMessage(object): @@ -650,6 +661,7 @@ class TestArrayAssertLess(object): assert_raises(AssertionError, lambda: self._assert_func(-ainf, -x)) self._assert_func(-ainf, x) + @pytest.mark.skip(reason="The raises decorator depends on Nose") class TestRaises(object): -- cgit v1.2.1 From 3ad49aaaf497c6daadb9b66f295f58a315476e01 Mon Sep 17 00:00:00 2001 From: Marten van Kerkwijk Date: Sun, 27 May 2018 13:15:16 -0400 Subject: MAINT: clean up assert_array_compare a bit further. This brought to light two bugs in tests, which are fixed here, viz., that a sample ndarray subclass that tested propagation of an added parameter was incomplete, in that in propagating the parameter in __array_wrap__ it assumed it was there on self, but that assumption could be broken when a view of self was taken (as is done by x[~flagged] in the test routine), since there was no __array_finalize__ defined. The other subclass bug counted, incorrectly, on only needing to provide one type of comparison, the __lt__ being explicitly tested. But flags are compared with __eq__ and those flags will have the same subclass. --- numpy/testing/tests/test_utils.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 235b3750c..465c217d4 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -401,6 +401,9 @@ class TestArrayAlmostEqual(_GenericTest): # comparison operators, not on them being able to store booleans # (which, e.g., astropy Quantity cannot usefully do). See gh-8452. class MyArray(np.ndarray): + def __eq__(self, other): + return super(MyArray, self).__eq__(other).view(np.ndarray) + def __lt__(self, other): return super(MyArray, self).__lt__(other).view(np.ndarray) @@ -500,6 +503,9 @@ class TestAlmostEqual(_GenericTest): # comparison operators, not on them being able to store booleans # (which, e.g., astropy Quantity cannot usefully do). See gh-8452. class MyArray(np.ndarray): + def __eq__(self, other): + return super(MyArray, self).__eq__(other).view(np.ndarray) + def __lt__(self, other): return super(MyArray, self).__lt__(other).view(np.ndarray) -- cgit v1.2.1