File tree 2 files changed +7
-3
lines changed
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):
1464
1464
names = set ([obj .name for obj in to_concat ])
1465
1465
name = None if len (names ) > 1 else self .name
1466
1466
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
+
1467
1472
typs = _concat .get_dtype_kinds (to_concat )
1468
1473
1469
1474
if len (typs ) == 1 :
Original file line number Diff line number Diff line change @@ -272,12 +272,11 @@ def test_append(self):
272
272
273
273
# with objects
274
274
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 )
277
276
tm .assert_index_equal (result , expected , exact = True )
278
277
279
278
# invalid objects
280
- # self.assertRaises(TypeError, lambda: ci.append(Index(['a', 'd'])))
279
+ self .assertRaises (TypeError , lambda : ci .append (Index (['a' , 'd' ])))
281
280
282
281
# GH14298 - if base object is not categorical -> coerce to object
283
282
result = Index (['c' , 'a' ]).append (ci )
You can’t perform that action at this time.
0 commit comments