From 6871bd52c82b9da6fb38e6c5caef64b82233b8b5 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 25 Jul 2025 04:01:40 +0530 Subject: [PATCH 01/17] BUG: Fix TypeError in assert_index_equal when comparing CategoricalIndex with check_categorical=True and exact=False --- pandas/_testing/asserters.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 2e5f8c372f7ef..34bd4f85b958a 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -325,7 +325,10 @@ def _check_types(left, right, obj: str = "Index") -> None: # skip exact index checking when `check_categorical` is False elif check_exact and check_categorical: if not left.equals(right): - mismatch = left._values != right._values + try: + mismatch = left._values != right._values + except TypeError as e: + raise AssertionError(f"{obj} cannot be compared due to incompatible categorical types.\n{e}") from e if not isinstance(mismatch, np.ndarray): mismatch = cast("ExtensionArray", mismatch).fillna(True) From d637203d263743b3de51c4b6e077b20a33402903 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 25 Jul 2025 05:20:13 +0530 Subject: [PATCH 02/17] STYLE: Fix E501 line too long in assert_index_equal error message --- pandas/_testing/asserters.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 34bd4f85b958a..e0752830a0abc 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -328,7 +328,9 @@ def _check_types(left, right, obj: str = "Index") -> None: try: mismatch = left._values != right._values except TypeError as e: - raise AssertionError(f"{obj} cannot be compared due to incompatible categorical types.\n{e}") from e + raise AssertionError( + f"{obj} cannot be compared due to incompatible categorical types.\n{e}" + ) from e if not isinstance(mismatch, np.ndarray): mismatch = cast("ExtensionArray", mismatch).fillna(True) From 7a4aae60ac0cf01fd620ccf4cf348d91d78e2332 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 25 Jul 2025 05:27:12 +0530 Subject: [PATCH 03/17] TST: Add test case for categorical index assertion fix --- pandas/_testing/asserters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index e0752830a0abc..891b04888db7a 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -329,7 +329,8 @@ def _check_types(left, right, obj: str = "Index") -> None: mismatch = left._values != right._values except TypeError as e: raise AssertionError( - f"{obj} cannot be compared due to incompatible categorical types.\n{e}" + f"{obj} cannot be compared due to incompatible" + f"categorical types.\n{e}" ) from e if not isinstance(mismatch, np.ndarray): From 1a7c48c1050532492e065a6eb19c401032ad81d2 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 25 Jul 2025 23:23:04 +0530 Subject: [PATCH 04/17] BUG: Fix (GH#61941) and unit test --- pandas/_testing/asserters.py | 4 +++- pandas/tests/util/test_assert_index_equal.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 891b04888db7a..336c23d913f98 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -326,7 +326,9 @@ def _check_types(left, right, obj: str = "Index") -> None: elif check_exact and check_categorical: if not left.equals(right): try: - mismatch = left._values != right._values + mismatch = ( + left._internal_get_values() != right._internal_get_values() + ) except TypeError as e: raise AssertionError( f"{obj} cannot be compared due to incompatible" diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index ab52d6c8e9f39..9786a2f552e00 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -317,3 +317,11 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) else: tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) + +def test_assert_index_equal_categorical_mismatch_categories(): + # GH#61941 + left = CategoricalIndex(["a", "b"], categories=["a", "b"]) + right = CategoricalIndex(["a", "b"], categories=["b", "a"]) + + with pytest.raises(AssertionError, match="cannot be compared due to incompatible"): + tm.assert_index_equal(left, right, check_exact=True, check_categorical=True) From d600c0687cf4799367d728b7445081b3c6062ef2 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 26 Jul 2025 14:28:15 +0530 Subject: [PATCH 05/17] Add unit test and (GH#61941) --- pandas/_testing/asserters.py | 11 +++-------- pandas/tests/util/test_assert_index_equal.py | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 336c23d913f98..4cefba18b6c05 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -326,14 +326,9 @@ def _check_types(left, right, obj: str = "Index") -> None: elif check_exact and check_categorical: if not left.equals(right): try: - mismatch = ( - left._internal_get_values() != right._internal_get_values() - ) - except TypeError as e: - raise AssertionError( - f"{obj} cannot be compared due to incompatible" - f"categorical types.\n{e}" - ) from e + mismatch = left._values != right._values + except TypeError : + mismatch = left._internal_get_values() != right._internal_get_values() if not isinstance(mismatch, np.ndarray): mismatch = cast("ExtensionArray", mismatch).fillna(True) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index 9786a2f552e00..3af14f58a7999 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -320,8 +320,8 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): def test_assert_index_equal_categorical_mismatch_categories(): # GH#61941 - left = CategoricalIndex(["a", "b"], categories=["a", "b"]) - right = CategoricalIndex(["a", "b"], categories=["b", "a"]) + ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) + ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False) - with pytest.raises(AssertionError, match="cannot be compared due to incompatible"): - tm.assert_index_equal(left, right, check_exact=True, check_categorical=True) + with pytest.raises(AssertionError, match="Index are different"): + tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True) \ No newline at end of file From eaeb094bf4ca2f4c2e4828c814e2a1b72f30e289 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 26 Jul 2025 15:42:08 +0530 Subject: [PATCH 06/17] Add unit test and (GH#61941) --- pandas/tests/util/test_assert_index_equal.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index 3af14f58a7999..38bce762080a0 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -322,6 +322,5 @@ def test_assert_index_equal_categorical_mismatch_categories(): # GH#61941 ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False) - with pytest.raises(AssertionError, match="Index are different"): - tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True) \ No newline at end of file + tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True) From 7037a72dba2d271b0905e78b1ec89fd270b5a3c2 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 26 Jul 2025 16:38:26 +0530 Subject: [PATCH 07/17] Add unit test and (GH#61941) --- pandas/tests/util/test_assert_index_equal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index 38bce762080a0..db7c6287bcfff 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -322,5 +322,7 @@ def test_assert_index_equal_categorical_mismatch_categories(): # GH#61941 ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False) + with pytest.raises(AssertionError, match="Index are different"): tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True) + \ No newline at end of file From 80aaf2c0842850e439adfaab38d4d912e9142060 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 26 Jul 2025 17:17:21 +0530 Subject: [PATCH 08/17] TST: Fix formatting in test_assert_index_equal (via pre-commit) --- pandas/tests/util/test_assert_index_equal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index db7c6287bcfff..bbda55e86ca30 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -318,11 +318,11 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): else: tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) + def test_assert_index_equal_categorical_mismatch_categories(): # GH#61941 ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False) - + with pytest.raises(AssertionError, match="Index are different"): tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True) - \ No newline at end of file From 1a1ee917f8c953e34a98a15a0a3d588e4e8d9826 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 26 Jul 2025 20:03:09 +0530 Subject: [PATCH 09/17] style: fix formatting with pre-commit (Ruff) --- pandas/_testing/asserters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 4cefba18b6c05..f41488f884c23 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -327,8 +327,8 @@ def _check_types(left, right, obj: str = "Index") -> None: if not left.equals(right): try: mismatch = left._values != right._values - except TypeError : - mismatch = left._internal_get_values() != right._internal_get_values() + except TypeError: + mismatch = left._internal_get_values() != right._internal_get_values() if not isinstance(mismatch, np.ndarray): mismatch = cast("ExtensionArray", mismatch).fillna(True) From 5419cf04c098d6dc3aa989d54943f74b8fdad1dc Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 26 Jul 2025 20:52:07 +0530 Subject: [PATCH 10/17] Fix: Check fail --- pandas/_testing/asserters.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index f41488f884c23..9eb83b4ff3fe8 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -328,7 +328,14 @@ def _check_types(left, right, obj: str = "Index") -> None: try: mismatch = left._values != right._values except TypeError: - mismatch = left._internal_get_values() != right._internal_get_values() + if hasattr(left, "_internal_get_values") and hasattr( + right, "_internal_get_values" + ): + mismatch = ( + left._internal_get_values() != right._internal_get_values() + ) + else: + mismatch = left.values != right.values if not isinstance(mismatch, np.ndarray): mismatch = cast("ExtensionArray", mismatch).fillna(True) From db8006daa1fdc5d9d2bc6834b207d5640b4e8093 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Mon, 28 Jul 2025 23:12:11 +0530 Subject: [PATCH 11/17] TST: Add test for CategoricalIndex vs Index in assert_index_equal --- pandas/tests/util/test_assert_index_equal.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index bbda55e86ca30..caf33f16638f1 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -321,8 +321,11 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): def test_assert_index_equal_categorical_mismatch_categories(): # GH#61941 - ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) - ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False) + ci = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) + idx = Index(["a", "b", "c"]) with pytest.raises(AssertionError, match="Index are different"): - tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True) + tm.assert_index_equal( + ci, + idx, + ) From 2ba4cfb673df3af76aa8ea135d01f260d33ae56e Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Tue, 29 Jul 2025 00:48:07 +0530 Subject: [PATCH 12/17] TST: Use isinstance for CategoricalIndex in assert_index_equal --- pandas/_testing/asserters.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 9eb83b4ff3fe8..3d4578a3c2f68 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -38,6 +38,7 @@ import pandas as pd from pandas import ( Categorical, + CategoricalIndex, DataFrame, DatetimeIndex, Index, @@ -328,8 +329,8 @@ def _check_types(left, right, obj: str = "Index") -> None: try: mismatch = left._values != right._values except TypeError: - if hasattr(left, "_internal_get_values") and hasattr( - right, "_internal_get_values" + if isinstance(left, CategoricalIndex) and isinstance( + right, CategoricalIndex ): mismatch = ( left._internal_get_values() != right._internal_get_values() From b82f8675c244ece99e6c66f900618502d73a3985 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Tue, 29 Jul 2025 23:37:10 +0530 Subject: [PATCH 13/17] Use the public .codes property for internal comparison of CategoricalIndex --- pandas/_testing/asserters.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 3d4578a3c2f68..550b42aa810c2 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -332,9 +332,7 @@ def _check_types(left, right, obj: str = "Index") -> None: if isinstance(left, CategoricalIndex) and isinstance( right, CategoricalIndex ): - mismatch = ( - left._internal_get_values() != right._internal_get_values() - ) + mismatch = left.codes != right.codes else: mismatch = left.values != right.values From 901297259d6197bda16539e5015d0d2f9499ec43 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Fri, 15 Aug 2025 15:21:43 +0530 Subject: [PATCH 14/17] TST: Add tests for CategoricalIndex mismatch scenarios --- pandas/tests/util/test_assert_index_equal.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index caf33f16638f1..4c0d87da70f7e 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -320,7 +320,7 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): def test_assert_index_equal_categorical_mismatch_categories(): - # GH#61941 + # GH#61941 - CategoricalIndex vs Index ci = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) idx = Index(["a", "b", "c"]) @@ -329,3 +329,15 @@ def test_assert_index_equal_categorical_mismatch_categories(): ci, idx, ) + + +def test_assert_categorical_index_equal_mismatch_categories(): + # GH#61941 - both left and right are CategoricalIndex + ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) + ci2 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "d"], ordered=False) + + with pytest.raises(AssertionError, match="Index are different"): + tm.assert_index_equal( + ci1, + ci2, + ) From b99e6d21a1d784f8592cd3cc7f2cca40e02339b0 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 27 Sep 2025 10:31:26 +0530 Subject: [PATCH 15/17] BUG: assert_index_equal CategoricalIndex incomparable categories gives AssertionError --- doc/source/whatsnew/v3.0.0.rst | 3 ++- pandas/_testing/asserters.py | 14 +++++----- pandas/tests/util/test_assert_index_equal.py | 28 +++++--------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 99a6be03c84d3..40572ef5e132f 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -936,7 +936,8 @@ Categorical - Bug in :meth:`Categorical.astype` where ``copy=False`` would still trigger a copy of the codes (:issue:`62000`) - Bug in :meth:`DataFrame.pivot` and :meth:`DataFrame.set_index` raising an ``ArrowNotImplementedError`` for columns with pyarrow dictionary dtype (:issue:`53051`) - Bug in :meth:`Series.convert_dtypes` with ``dtype_backend="pyarrow"`` where empty :class:`CategoricalDtype` :class:`Series` raised an error or got converted to ``null[pyarrow]`` (:issue:`59934`) -- +- Bug in :func:`testing.assert_index_equal` raising ``TypeError`` instead of ``AssertionError`` for incomparable ``CategoricalIndex`` when ``check_categorical=True`` and ``exact=False`` (:issue:`61935`) +- Datetimelike ^^^^^^^^^^^^ diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 550b42aa810c2..4ed0123345b65 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -38,7 +38,6 @@ import pandas as pd from pandas import ( Categorical, - CategoricalIndex, DataFrame, DatetimeIndex, Index, @@ -326,15 +325,16 @@ def _check_types(left, right, obj: str = "Index") -> None: # skip exact index checking when `check_categorical` is False elif check_exact and check_categorical: if not left.equals(right): + # _values compare can raise TypeError for non-comparable categoricals (GH#61935) try: mismatch = left._values != right._values except TypeError: - if isinstance(left, CategoricalIndex) and isinstance( - right, CategoricalIndex - ): - mismatch = left.codes != right.codes - else: - mismatch = left.values != right.values + raise_assert_detail( + obj, + "types are not comparable (non-matching categorical categories)", + left, + right, + ) if not isinstance(mismatch, np.ndarray): mismatch = cast("ExtensionArray", mismatch).fillna(True) diff --git a/pandas/tests/util/test_assert_index_equal.py b/pandas/tests/util/test_assert_index_equal.py index 4c0d87da70f7e..8baabe97a3219 100644 --- a/pandas/tests/util/test_assert_index_equal.py +++ b/pandas/tests/util/test_assert_index_equal.py @@ -319,25 +319,9 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical): tm.assert_index_equal(idx1, idx2, check_categorical=check_categorical) -def test_assert_index_equal_categorical_mismatch_categories(): - # GH#61941 - CategoricalIndex vs Index - ci = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) - idx = Index(["a", "b", "c"]) - - with pytest.raises(AssertionError, match="Index are different"): - tm.assert_index_equal( - ci, - idx, - ) - - -def test_assert_categorical_index_equal_mismatch_categories(): - # GH#61941 - both left and right are CategoricalIndex - ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False) - ci2 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "d"], ordered=False) - - with pytest.raises(AssertionError, match="Index are different"): - tm.assert_index_equal( - ci1, - ci2, - ) +def test_assert_index_equal_categorical_incomparable_categories(): + # GH#61935 + left = Index([1, 2, 3], name="a", dtype="category") + right = Index([1, 2, 6], name="a", dtype="category") + with pytest.raises(AssertionError, match="types are not comparable"): + tm.assert_index_equal(left, right, check_categorical=True, exact=False) From 5d4af24ac4f749076a6d5779b32760f382267520 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 27 Sep 2025 10:57:07 +0530 Subject: [PATCH 16/17] BUG: assert_index_equal CategoricalIndex incomparable categories gives AssertionError --- doc/source/whatsnew/v3.0.0.rst | 5 ++--- pandas/_testing/asserters.py | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 40572ef5e132f..4f19431625e5a 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -933,11 +933,10 @@ Bug fixes Categorical ^^^^^^^^^^^ - Bug in :func:`Series.apply` where ``nan`` was ignored for :class:`CategoricalDtype` (:issue:`59938`) -- Bug in :meth:`Categorical.astype` where ``copy=False`` would still trigger a copy of the codes (:issue:`62000`) +- Bug in :func:`testing.assert_index_equal` raising ``TypeError`` instead of ``AssertionError`` for incomparable ``CategoricalIndex`` when ``check_categorical=True`` and ``exact=False`` (:issue:`61935`) - Bug in :meth:`DataFrame.pivot` and :meth:`DataFrame.set_index` raising an ``ArrowNotImplementedError`` for columns with pyarrow dictionary dtype (:issue:`53051`) - Bug in :meth:`Series.convert_dtypes` with ``dtype_backend="pyarrow"`` where empty :class:`CategoricalDtype` :class:`Series` raised an error or got converted to ``null[pyarrow]`` (:issue:`59934`) -- Bug in :func:`testing.assert_index_equal` raising ``TypeError`` instead of ``AssertionError`` for incomparable ``CategoricalIndex`` when ``check_categorical=True`` and ``exact=False`` (:issue:`61935`) -- +- Datetimelike ^^^^^^^^^^^^ diff --git a/pandas/_testing/asserters.py b/pandas/_testing/asserters.py index 4ed0123345b65..c8f3bb6bd77d2 100644 --- a/pandas/_testing/asserters.py +++ b/pandas/_testing/asserters.py @@ -325,7 +325,8 @@ def _check_types(left, right, obj: str = "Index") -> None: # skip exact index checking when `check_categorical` is False elif check_exact and check_categorical: if not left.equals(right): - # _values compare can raise TypeError for non-comparable categoricals (GH#61935) + # _values compare can raise TypeError (non-comparable + # categoricals (GH#61935) try: mismatch = left._values != right._values except TypeError: From bc10d925bd45c835892779a96c536d7c262b98bd Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Sat, 27 Sep 2025 11:40:37 +0530 Subject: [PATCH 17/17] BUG: assert_index_equal CategoricalIndex incomparable categories gives AssertionError --- doc/source/whatsnew/v3.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 4f19431625e5a..f33ae03f46225 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -934,6 +934,7 @@ Categorical ^^^^^^^^^^^ - Bug in :func:`Series.apply` where ``nan`` was ignored for :class:`CategoricalDtype` (:issue:`59938`) - Bug in :func:`testing.assert_index_equal` raising ``TypeError`` instead of ``AssertionError`` for incomparable ``CategoricalIndex`` when ``check_categorical=True`` and ``exact=False`` (:issue:`61935`) +- Bug in :meth:`Categorical.astype` where ``copy=False`` would still trigger a copy of the codes (:issue:`62000`) - Bug in :meth:`DataFrame.pivot` and :meth:`DataFrame.set_index` raising an ``ArrowNotImplementedError`` for columns with pyarrow dictionary dtype (:issue:`53051`) - Bug in :meth:`Series.convert_dtypes` with ``dtype_backend="pyarrow"`` where empty :class:`CategoricalDtype` :class:`Series` raised an error or got converted to ``null[pyarrow]`` (:issue:`59934`) -