Skip to content

Commit 9e7a7bd

Browse files
committed
updated the code in accordance with GH24845
1 parent bf2ad96 commit 9e7a7bd

File tree

1 file changed

+3
-33
lines changed

1 file changed

+3
-33
lines changed

pandas/core/indexes/category.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -569,41 +569,14 @@ def map(self, mapper):
569569
mapped = self._values.map(mapper)
570570
return Index(mapped, name=self.name)
571571

572-
def _permutation_check(self, to_concat) -> bool:
573-
# GH40378 - we have to check if they are permutations.
574-
# If they are, we have to create a fix, in order to
575-
# prevent the error discussed in the named issue
576-
permutations = True
577-
category1 = CategoricalIndex(
578-
[],
579-
categories=to_concat[0]._is_dtype_compat(to_concat[0]).categories,
580-
ordered=False,
581-
)
582-
for i in to_concat[1:]:
583-
category2 = CategoricalIndex(
584-
[], categories=i._is_dtype_compat(i).categories, ordered=False
585-
)
586-
if not category1.equals(category2):
587-
permutations = False
588-
589-
return permutations
590-
591572
def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
592573
# if calling index is category, don't check dtype of others
593574

594-
cat_index = True
595-
596-
for i in to_concat:
597-
if not isinstance(i, CategoricalIndex):
598-
cat_index = False
599-
break
600-
601575
try:
602-
if cat_index:
603-
if self._permutation_check(to_concat):
604-
raise TypeError
605576

606-
codes = np.concatenate([self._is_dtype_compat(c).codes for c in to_concat])
577+
result = Categorical._concat_same_type(list(to_concat))
578+
579+
return CategoricalIndex(result, name=name)
607580

608581
except TypeError:
609582
# not all to_concat elements are among our categories (or NA)
@@ -612,6 +585,3 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index:
612585
res = concat_compat([x._values for x in to_concat])
613586

614587
return Index(res, name=name)
615-
else:
616-
cat = self._data._from_backing_data(codes)
617-
return type(self)._simple_new(cat, name=name)

0 commit comments

Comments
 (0)