Skip to content

Commit 2b6d3a0

Browse files
committed
Add unit test and (GH#61941)
1 parent 5edf8ce commit 2b6d3a0

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

pandas/_testing/asserters.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,9 @@ def _check_types(left, right, obj: str = "Index") -> None:
323323
elif check_exact and check_categorical:
324324
if not left.equals(right):
325325
try:
326-
mismatch = (
327-
left._internal_get_values() != right._internal_get_values()
328-
)
329-
except TypeError as e:
330-
raise AssertionError(
331-
f"{obj} cannot be compared due to incompatible"
332-
f"categorical types.\n{e}"
333-
) from e
326+
mismatch = left._values != right._values
327+
except TypeError :
328+
mismatch = left._internal_get_values() != right._internal_get_values()
334329

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

pandas/tests/util/test_assert_index_equal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ def test_assert_multi_index_dtype_check_categorical(check_categorical):
320320

321321
def test_assert_index_equal_categorical_mismatch_categories():
322322
# GH#61941
323-
left = CategoricalIndex(["a", "b"], categories=["a", "b"])
324-
right = CategoricalIndex(["a", "b"], categories=["b", "a"])
323+
ci1 = CategoricalIndex(["a", "b", "c"], categories=["a", "b", "c"], ordered=False)
324+
ci2 = CategoricalIndex(["a", "x", "c"], categories=["a", "b", "c"], ordered=False)
325325

326-
with pytest.raises(AssertionError, match="cannot be compared due to incompatible"):
327-
tm.assert_index_equal(left, right, check_exact=True, check_categorical=True)
326+
with pytest.raises(AssertionError, match="Index are different"):
327+
tm.assert_index_equal(ci1, ci2, check_exact=False, check_categorical=True)

0 commit comments

Comments
 (0)