BUG: assert_index_equal(CategoricalIndex, CategoricalIndex, check_categorical=True, exact=False) raises TypeError instead of AssertionError (original) (raw)

Pandas version checks

Reproducible Example

In [1]: import pandas as pd

In [2]: p_left = pd.Index([1, 2, 3], name="a", dtype="category")

In [3]: p_right = pd.Index([1, 2, 6], name="a", dtype="category")

In [4]: pd.testing.assert_index_equal(p_left, p_right, check_categorical=True, exact=False)

TypeError Traceback (most recent call last) Cell In[10], line 1 ----> 1 pd.testing.assert_index_equal(p_left, p_right, check_categorical=True, exact=False)

[... skipping hidden 1 frame]

File ~/pandas/core/ops/common.py:70, in _unpack_zerodim_and_defer..new_method(self, other) 66 return NotImplemented 68 other = item_from_zerodim(other) ---> 70 return method(self, other)

File ~/pandas/core/arrays/categorical.py:143, in _cat_compare_op..func(self, other) 141 msg = "Categoricals can only be compared if 'categories' are the same." 142 if not self._categories_match_up_to_permutation(other): --> 143 raise TypeError(msg) 145 if not self.ordered and not self.categories.equals(other.categories): 146 # both unordered and different order 147 other_codes = recode_for_categories( 148 other.codes, other.categories, self.categories, copy=False 149 )

TypeError: Categoricals can only be compared if 'categories' are the same.

Issue Description

pandas asserters should always raise an AssertionError.

Expected Behavior

I would expect this to raise an AssertionError.

Installed Versions

Replace this line with the output of pd.show_versions()