@@ -569,41 +569,14 @@ def map(self, mapper):
569
569
mapped = self ._values .map (mapper )
570
570
return Index (mapped , name = self .name )
571
571
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
-
591
572
def _concat (self , to_concat : list [Index ], name : Hashable ) -> Index :
592
573
# if calling index is category, don't check dtype of others
593
574
594
- cat_index = True
595
-
596
- for i in to_concat :
597
- if not isinstance (i , CategoricalIndex ):
598
- cat_index = False
599
- break
600
-
601
575
try :
602
- if cat_index :
603
- if self ._permutation_check (to_concat ):
604
- raise TypeError
605
576
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 )
607
580
608
581
except TypeError :
609
582
# 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:
612
585
res = concat_compat ([x ._values for x in to_concat ])
613
586
614
587
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