diff --git a/pandas/src/testing.pyx b/pandas/src/testing.pyx index b324c6652d58f..404b97879e2be 100644 --- a/pandas/src/testing.pyx +++ b/pandas/src/testing.pyx @@ -82,10 +82,12 @@ cpdef assert_almost_equal(a, b, bint check_less_precise=False): assert na == nb, ( "Length of two iterators not the same: %r != %r" % (na, nb) ) - if (isinstance(a, np.ndarray) and - isinstance(b, np.ndarray) and - np.array_equal(a, b)): - return True + if isinstance(a, np.ndarray) and isinstance(b, np.ndarray): + try: + if np.array_equal(a, b): + return True + except: + pass else: for i in xrange(na): assert_almost_equal(a[i], b[i], check_less_precise) diff --git a/pandas/tests/test_testing.py b/pandas/tests/test_testing.py index fa295838d47e9..8431d91a8fff6 100644 --- a/pandas/tests/test_testing.py +++ b/pandas/tests/test_testing.py @@ -48,6 +48,12 @@ def test_assert_almost_equal_numbers_with_mixed(self): self._assert_not_almost_equal_both(1, [1,]) self._assert_not_almost_equal_both(1, object()) + def test_assert_almost_equal_edge_case_ndarrays(self): + self._assert_almost_equal_both(np.array([], dtype='M8[ns]'), + np.array([], dtype='float64')) + self._assert_almost_equal_both(np.array([], dtype=str), + np.array([], dtype='int64')) + def test_assert_almost_equal_dicts(self): self._assert_almost_equal_both({'a': 1, 'b': 2}, {'a': 1, 'b': 2}) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 413b5f8426d71..f40a8e1a5a9d6 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -411,9 +411,9 @@ def assert_series_equal(left, right, check_dtype=True, check_less_precise=False): if check_series_type: assert_isinstance(left, type(right)) - assert_almost_equal(left.values, right.values, check_less_precise) if check_dtype: assert_attr_equal('dtype', left, right) + assert_almost_equal(left.values, right.values, check_less_precise) if check_less_precise: assert_almost_equal( left.index.values, right.index.values, check_less_precise)