diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index a5e8edca80873..ff014ac249fc3 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -235,20 +235,23 @@ def _shallow_copy(self, values=None, name: Label = no_default): return super()._shallow_copy(values=values, name=name) - def _is_dtype_compat(self, other) -> bool: + def _is_dtype_compat(self, other) -> Categorical: """ *this is an internal non-public method* provide a comparison between the dtype of self and other (coercing if needed) + Returns + ------- + Categorical + Raises ------ TypeError if the dtypes are not compatible """ if is_categorical_dtype(other): - if isinstance(other, CategoricalIndex): - other = other._values + other = extract_array(other) if not other.is_dtype_equal(self): raise TypeError( "categories must match existing categories when appending" @@ -263,6 +266,7 @@ def _is_dtype_compat(self, other) -> bool: raise TypeError( "cannot append a non-category item to a CategoricalIndex" ) + other = other._values return other