Skip to content

Commit 5029592

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

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-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

+4
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,10 @@ 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+
return CategoricalIndex._append_same_dtype(self, to_concat, name)
639+
636640
def _append_same_dtype(self, to_concat, name):
637641
"""
638642
Concatenate to_concat which has the same class

0 commit comments

Comments
 (0)