From e5257c53826b1def010d79695748a4c2995c991f Mon Sep 17 00:00:00 2001 From: Jayendra Date: Sun, 26 Mar 2023 11:59:42 +0530 Subject: [PATCH 1/3] Added check_categorical argument in assert_index_equal recursive call --- pandas/_testing/asserters.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index e25e8388bc4cd..3d46d0864b91f 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -294,6 +294,7 @@ def _get_ilevel_values(index, level): exact=exact, check_names=check_names, check_exact=check_exact, + check_categorical=check_categorical, rtol=rtol, atol=atol, obj=lobj, From cfcfbfc39f02465f200eb0ef99ddd22e933dbb24 Mon Sep 17 00:00:00 2001 From: Jayendra Date: Sun, 26 Mar 2023 12:39:22 +0530 Subject: [PATCH 2/3] Added test cases --- pandas/tests/util/test_assert_index_equal.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index f7d41ed536a40..fcc9757a4db0d 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -298,3 +298,16 @@ def test_assert_ea_index_equal_non_matching_na(check_names, check_categorical): tm.assert_index_equal( idx1, idx2, check_names=check_names, check_categorical=check_categorical ) + + +@pytest.mark.parametrize("check_categorical", [True, False]) +def test_assert_multi_index_dtype_check_categorical(check_categorical): + idx1 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.uint64))]) + idx2 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.int64))]) + if check_categorical: + with pytest.raises( + AssertionError, match=r"^MultiIndex level \[0\] are different" + ): + tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) + else: + tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) From f24dbdcc5d5da37630099acf3a95b2ac0ede73b7 Mon Sep 17 00:00:00 2001 From: Jayendra Date: Sat, 1 Apr 2023 09:30:55 +0530 Subject: [PATCH 3/3] Added whatsnew entry and mentioned issue number for test --- doc/source/whatsnew/v2.1.0.rst | 1 + pandas/tests/util/test_assert_index_equal.py | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 1f5c3c88c5ff5..7c3e43815d0c8 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -259,6 +259,7 @@ Other ^^^^^ - Bug in :func:`assert_almost_equal` now throwing assertion error for two unequal sets (:issue:`51727`) - Bug in :meth:`Series.memory_usage` when ``deep=True`` throw an error with Series of objects and the returned value is incorrect, as it does not take into account GC corrections (:issue:`51858`) +- Bug in :func:`assert_frame_equal` checks category dtypes even when asked not to check index type (:issue:`52126`) .. ***DO NOT USE THIS SECTION*** diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index fcc9757a4db0d..a48eeb5be8005 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -302,6 +302,7 @@ def test_assert_ea_index_equal_non_matching_na(check_names, check_categorical): @pytest.mark.parametrize("check_categorical", [True, False]) def test_assert_multi_index_dtype_check_categorical(check_categorical): + # GH#52126 idx1 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.uint64))]) idx2 = MultiIndex.from_arrays([Categorical(np.array([1, 2], dtype=np.int64))]) if check_categorical: