From e37d16136473acbc9d5a3c51ea396464a207b66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon-Martin=20Schr=C3=B6der?= Date: Tue, 15 Oct 2019 11:13:13 +0200 Subject: [PATCH 1/4] ENH: Informative dtype message for for assert_series_equal Pass obj to assert_attr_equal in assert_series_equal. --- pandas/util/testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 4cf2776f5aa7c..9ac1aaf1e0dab 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1156,7 +1156,7 @@ def assert_series_equal( ): pass else: - assert_attr_equal("dtype", left, right) + assert_attr_equal("dtype", left, right, obj="Attributes of {obj}".format(obj=obj)) if check_exact: assert_numpy_array_equal( From 9f175c2adca8be0b9dd53efc8c794654dde196b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon-Martin=20Schr=C3=B6der?= Date: Tue, 15 Oct 2019 11:30:38 +0200 Subject: [PATCH 2/4] Update tests, change whitespace --- pandas/tests/util/test_assert_frame_equal.py | 2 +- pandas/util/testing.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_assert_frame_equal.py b/pandas/tests/util/test_assert_frame_equal.py index 9571e8027ccf7..86e5d506e0779 100644 --- a/pandas/tests/util/test_assert_frame_equal.py +++ b/pandas/tests/util/test_assert_frame_equal.py @@ -141,7 +141,7 @@ def test_empty_dtypes(check_dtype): df1["col1"] = df1["col1"].astype("int64") if check_dtype: - msg = "Attributes are different" + msg = r"Attributes of DataFrame\..* are different" with pytest.raises(AssertionError, match=msg): assert_frame_equal(df1, df2, **kwargs) else: diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 9ac1aaf1e0dab..28c4b3e5169fd 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1156,7 +1156,9 @@ def assert_series_equal( ): pass else: - assert_attr_equal("dtype", left, right, obj="Attributes of {obj}".format(obj=obj)) + assert_attr_equal( + "dtype", left, right, obj="Attributes of {obj}".format(obj=obj) + ) if check_exact: assert_numpy_array_equal( From af4a8a4f5be2a4211a9872aed28a177c76af10ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon-Martin=20Schr=C3=B6der?= Date: Tue, 15 Oct 2019 13:27:08 +0200 Subject: [PATCH 3/4] Update example --- pandas/util/testing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 28c4b3e5169fd..73535e55d4fa5 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1317,8 +1317,9 @@ def assert_frame_equal( >>> assert_frame_equal(df1, df2) Traceback (most recent call last): - AssertionError: Attributes are different ... + AssertionError: Attributes of DataFrame.iloc[:, 1] are different + Attribute "dtype" are different [left]: int64 [right]: float64 From a5cfdcdd3c576e47a707f140007cf1029f0fc491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon-Martin=20Schr=C3=B6der?= Date: Tue, 15 Oct 2019 15:21:17 +0200 Subject: [PATCH 4/4] Adapt test_series_equal_categorical_mismatch --- pandas/tests/util/test_assert_series_equal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index a12d9386eb159..bad3f2e67f8bb 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -179,7 +179,7 @@ def test_series_equal_values_mismatch(check_less_precise): def test_series_equal_categorical_mismatch(check_categorical): - msg = """Attributes are different + msg = """Attributes of Series are different Attribute "dtype" are different \\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False\\)