Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6871bd5
BUG: Fix TypeError in assert_index_equal when comparing CategoricalIn…
Aniketsy Jul 24, 2025
d637203
STYLE: Fix E501 line too long in assert_index_equal error message
Aniketsy Jul 24, 2025
7a4aae6
TST: Add test case for categorical index assertion fix
Aniketsy Jul 24, 2025
1a7c48c
BUG: Fix (GH#61941) and unit test
Aniketsy Jul 25, 2025
d600c06
Add unit test and (GH#61941)
Aniketsy Jul 26, 2025
eaeb094
Add unit test and (GH#61941)
Aniketsy Jul 26, 2025
7037a72
Add unit test and (GH#61941)
Aniketsy Jul 26, 2025
80aaf2c
TST: Fix formatting in test_assert_index_equal (via pre-commit)
Aniketsy Jul 26, 2025
1a1ee91
style: fix formatting with pre-commit (Ruff)
Aniketsy Jul 26, 2025
5419cf0
Fix: Check fail
Aniketsy Jul 26, 2025
db8006d
TST: Add test for CategoricalIndex vs Index in assert_index_equal
Aniketsy Jul 28, 2025
2ba4cfb
TST: Use isinstance for CategoricalIndex in assert_index_equal
Aniketsy Jul 28, 2025
b82f867
Use the public .codes property for internal comparison of Categorical…
Aniketsy Jul 29, 2025
9012972
TST: Add tests for CategoricalIndex mismatch scenarios
Aniketsy Aug 15, 2025
b99e6d2
BUG: assert_index_equal CategoricalIndex incomparable categories give…
Aniketsy Sep 27, 2025
5d4af24
BUG: assert_index_equal CategoricalIndex incomparable categories give…
Aniketsy Sep 27, 2025
bc10d92
BUG: assert_index_equal CategoricalIndex incomparable categories give…
Aniketsy Sep 27, 2025
ac62aa5
Merge remote-tracking branch 'upstream/main' into bugfix-assert-categ…
Aniketsy Oct 1, 2025
6ef5a73
Merge branch 'main' into bugfix-assert-categoricalindex-typeerror
Aniketsy Oct 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ Bug fixes
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`)
Expand Down
12 changes: 11 additions & 1 deletion pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,17 @@ 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
# _values compare can raise TypeError (non-comparable
# categoricals (GH#61935)
try:
mismatch = left._values != right._values
except TypeError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment pointing back to the original issue, otherwise ill be confused as to why this can happen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure , I will add comment

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)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/util/test_assert_index_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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)
Loading