Skip to content

Commit

Permalink
REF: use inheritance to concatenate categorical Indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
toobaz committed Aug 10, 2017
1 parent 7bef6d8 commit 5029592
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,10 +1741,9 @@ def append(self, other):
names = set([obj.name for obj in to_concat])
name = None if len(names) > 1 else self.name

if self.is_categorical():
# if calling index is category, don't check dtype of others
from pandas.core.indexes.category import CategoricalIndex
return CategoricalIndex._append_same_dtype(self, to_concat, name)
return self._concat(to_concat, name)

def _concat(self, to_concat, name):

typs = _concat.get_dtype_kinds(to_concat)

Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ def insert(self, loc, item):
codes = np.concatenate((codes[:loc], code, codes[loc:]))
return self._create_from_codes(codes)

def _concat(self, to_concat, name):
# if calling index is category, don't check dtype of others
return CategoricalIndex._append_same_dtype(self, to_concat, name)

def _append_same_dtype(self, to_concat, name):
"""
Concatenate to_concat which has the same class
Expand Down

0 comments on commit 5029592

Please sign in to comment.