diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-09-05 00:57:48 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2014-09-05 00:57:48 +0200 |
commit | 859d2f13c6a603c904701f509bd0bc52efb31295 (patch) | |
tree | 91470cb38ed7a498b19eb45e88f05965f061ac7b | |
parent | 90cac3cb8bb4534f7f760d7fc3f82cdf0d517524 (diff) | |
parent | dfc567790badcc87822a39f5c35f0dd78b8c1599 (diff) | |
download | numpy-859d2f13c6a603c904701f509bd0bc52efb31295.tar.gz |
Merge pull request #5048 from juliantaylor/subclass-test-fix
BUG: fix array_almost_equal for array subclasses
-rw-r--r-- | numpy/testing/tests/test_utils.py | 8 | ||||
-rw-r--r-- | numpy/testing/utils.py | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index aa0a2669f..41a48ea65 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -244,6 +244,14 @@ class TestArrayAlmostEqual(_GenericTest, unittest.TestCase): self.assertRaises(AssertionError, lambda : self._assert_func(a, b)) + def test_subclass(self): + a = np.array([[1., 2.], [3., 4.]]) + b = np.ma.masked_array([[1., 2.], [0., 4.]], + [[False, False], [True, False]]) + assert_array_almost_equal(a, b) + assert_array_almost_equal(b, a) + assert_array_almost_equal(b, b) + class TestAlmostEqual(_GenericTest, unittest.TestCase): def setUp(self): self._assert_func = assert_almost_equal diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py index bd184d922..4f45f62f4 100644 --- a/numpy/testing/utils.py +++ b/numpy/testing/utils.py @@ -829,7 +829,7 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) - y = array(y, dtype=dtype, copy=False) + y = array(y, dtype=dtype, copy=False, subok=True) z = abs(x-y) if not issubdtype(z.dtype, number): |