Skip to content

Commit 085caa1

Browse files
committed
BUG: Fix TypeError in assert_index_equal when comparing CategoricalIndex with check_categorical=True and exact=False
1 parent e72c8a1 commit 085caa1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pandas/_testing/asserters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ def _check_types(left, right, obj: str = "Index") -> None:
322322
# skip exact index checking when `check_categorical` is False
323323
elif check_exact and check_categorical:
324324
if not left.equals(right):
325-
mismatch = left._values != right._values
325+
try:
326+
mismatch = left._values != right._values
327+
except TypeError as e:
328+
raise AssertionError(f"{obj} cannot be compared due to incompatible categorical types.\n{e}") from e
326329

327330
if not isinstance(mismatch, np.ndarray):
328331
mismatch = cast("ExtensionArray", mismatch).fillna(True)

0 commit comments

Comments
 (0)