File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -1464,6 +1464,11 @@ def append(self, other):
14641464 names = set ([obj .name for obj in to_concat ])
14651465 name = None if len (names ) > 1 else self .name
14661466
1467+ if self .is_categorical ():
1468+ # if any of the to_concat is category
1469+ from pandas .indexes .category import CategoricalIndex
1470+ return CategoricalIndex ._append_same_dtype (self , to_concat , name )
1471+
14671472 typs = _concat .get_dtype_kinds (to_concat )
14681473
14691474 if len (typs ) == 1 :
Original file line number Diff line number Diff line change @@ -272,12 +272,11 @@ def test_append(self):
272272
273273 # with objects
274274 result = ci .append (Index (['c' , 'a' ]))
275- #expected = CategoricalIndex(list('aabbcaca'), categories=categories)
276- expected = Index (list ('aabbcaca' ))
275+ expected = CategoricalIndex (list ('aabbcaca' ), categories = categories )
277276 tm .assert_index_equal (result , expected , exact = True )
278277
279278 # invalid objects
280- # self.assertRaises(TypeError, lambda: ci.append(Index(['a', 'd'])))
279+ self .assertRaises (TypeError , lambda : ci .append (Index (['a' , 'd' ])))
281280
282281 # GH14298 - if base object is not categorical -> coerce to object
283282 result = Index (['c' , 'a' ]).append (ci )
You can’t perform that action at this time.
0 commit comments