Skip to content

Commit 1f8e1bc

Browse files
committed
REF: use inheritance to concatenate categorical Indexes
1 parent 7bef6d8 commit 1f8e1bc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pandas/core/indexes/base.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1741,10 +1741,9 @@ def append(self, other):
17411741
names = set([obj.name for obj in to_concat])
17421742
name = None if len(names) > 1 else self.name
17431743

1744-
if self.is_categorical():
1745-
# if calling index is category, don't check dtype of others
1746-
from pandas.core.indexes.category import CategoricalIndex
1747-
return CategoricalIndex._append_same_dtype(self, to_concat, name)
1744+
return self._concat(to_concat, name)
1745+
1746+
def _concat(self, to_concat, name):
17481747

17491748
typs = _concat.get_dtype_kinds(to_concat)
17501749

pandas/core/indexes/category.py

+5
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ def insert(self, loc, item):
633633
codes = np.concatenate((codes[:loc], code, codes[loc:]))
634634
return self._create_from_codes(codes)
635635

636+
def _concat(self, to_concat, name):
637+
# if calling index is category, don't check dtype of others
638+
from pandas.core.indexes.category import CategoricalIndex
639+
return CategoricalIndex._append_same_dtype(self, to_concat, name)
640+
636641
def _append_same_dtype(self, to_concat, name):
637642
"""
638643
Concatenate to_concat which has the same class

0 commit comments

Comments
 (0)