Skip to content

Commit 9b76f7e

Browse files
BUG/API: Index.append with mixed object/Categorical indices
1 parent d7fb5bd commit 9b76f7e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

pandas/indexes/base.py

-5
Original file line numberDiff line numberDiff line change
@@ -1466,11 +1466,6 @@ def append(self, other):
14661466

14671467
typs = _concat.get_dtype_kinds(to_concat)
14681468

1469-
if 'category' in typs:
1470-
# if any of the to_concat is category
1471-
from pandas.indexes.category import CategoricalIndex
1472-
return CategoricalIndex._append_same_dtype(self, to_concat, name)
1473-
14741469
if len(typs) == 1:
14751470
return self._append_same_dtype(to_concat, name=name)
14761471
return _concat._concat_index_asobject(to_concat, name=name)

pandas/tests/indexes/test_category.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,17 @@ def test_append(self):
272272

273273
# with objects
274274
result = ci.append(Index(['c', 'a']))
275-
expected = CategoricalIndex(list('aabbcaca'), categories=categories)
275+
#expected = CategoricalIndex(list('aabbcaca'), categories=categories)
276+
expected = Index(list('aabbcaca'))
276277
tm.assert_index_equal(result, expected, exact=True)
277278

278279
# invalid objects
279-
self.assertRaises(TypeError, lambda: ci.append(Index(['a', 'd'])))
280+
#self.assertRaises(TypeError, lambda: ci.append(Index(['a', 'd'])))
281+
282+
# GH14298 - if base object is not categorical -> coerce to object
283+
result = Index(['c', 'a']).append(ci)
284+
expected = Index(list('caaabbca'))
285+
tm.assert_index_equal(result, expected, exact=True)
280286

281287
def test_insert(self):
282288

0 commit comments

Comments
 (0)