8000 Merge pull request #5048 from juliantaylor/subclass-test-fix · numpy/numpy@859d2f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 859d2f1

Browse files
committed
Merge pull request #5048 from juliantaylor/subclass-test-fix
BUG: fix array_almost_equal for array subclasses
2 parents 90cac3c + dfc5677 commit 859d2f1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

numpy/testing/tests/test_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ def test_inf(self):
244244
self.assertRaises(AssertionError,
245245
lambda : self._assert_func(a, b))
246246

247+
def test_subclass(self):
248+
a = np.array([[1., 2.], [3., 4.]])
249+
b = np.ma.masked_array([[1., 2.], [0., 4.]],
250+
[[False, False], [True, False]])
251+
assert_array_almost_equal(a, b)
252+
assert_array_almost_equal(b, a)
253+
assert_array_almost_equal(b, b)
254+
247255
class TestAlmostEqual(_GenericTest, unittest.TestCase):
248256
def setUp(self):
249257
self._assert_func = assert_almost_equal

numpy/testing/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ def compare(x, y):
829829
# make sure y is an inexact type to avoid abs(MIN_INT); will cause
830830
# casting of x later.
831831
dtype = result_type(y, 1.)
832-
y = array(y, dtype=dtype, copy=False)
832+
y = array(y, dtype=dtype, copy=False, subok=True)
833833
z = abs(x-y)
834834

835835
if not issubdtype(z.dtype, number):

0 commit comments

Comments
 (0)
0