Skip to content

Commit ea19bd9

Browse files
authored
REF: make casting explicit in CategoricalIndex (#37884)
1 parent 4c6feae commit ea19bd9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

pandas/core/indexes/category.py

+2
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
491491
# in which case we are going to conform to the passed Categorical
492492
new_target = np.asarray(new_target)
493493
if is_categorical_dtype(target):
494+
new_target = Categorical(new_target, dtype=target.dtype)
494495
new_target = target._shallow_copy(new_target, name=self.name)
495496
else:
496497
new_target = Index(new_target, name=self.name)
@@ -514,6 +515,7 @@ def _reindex_non_unique(self, target):
514515
if not (cats == -1).any():
515516
# .reindex returns normal Index. Revert to CategoricalIndex if
516517
# all targets are included in my categories
518+
new_target = Categorical(new_target, dtype=self.dtype)
517519
new_target = self._shallow_copy(new_target)
518520

519521
return new_target, indexer, new_indexer

0 commit comments

Comments
 (0)