Skip to content

Commit 7dcaaf4

Browse files
authored
TYP: is_dtype_compat (#37340)
1 parent b49aeac commit 7dcaaf4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pandas/core/indexes/category.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,23 @@ def _shallow_copy(self, values=None, name: Label = no_default):
235235

236236
return super()._shallow_copy(values=values, name=name)
237237

238-
def _is_dtype_compat(self, other) -> bool:
238+
def _is_dtype_compat(self, other) -> Categorical:
239239
"""
240240
*this is an internal non-public method*
241241
242242
provide a comparison between the dtype of self and other (coercing if
243243
needed)
244244
245+
Returns
246+
-------
247+
Categorical
248+
245249
Raises
246250
------
247251
TypeError if the dtypes are not compatible
248252
"""
249253
if is_categorical_dtype(other):
250-
if isinstance(other, CategoricalIndex):
251-
other = other._values
254+
other = extract_array(other)
252255
if not other.is_dtype_equal(self):
253256
raise TypeError(
254257
"categories must match existing categories when appending"
@@ -263,6 +266,7 @@ def _is_dtype_compat(self, other) -> bool:
263266
raise TypeError(
264267
"cannot append a non-category item to a CategoricalIndex"
265268
)
269+
other = other._values
266270

267271
return other
268272

0 commit comments

Comments
 (0)