Skip to content

Commit 0135b79

Browse files
authored
TST: Added test for upcasting to object when concatinating on categorical indexes with non-identical categories (#42278)
1 parent 1d4209d commit 0135b79

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/reshape/concat/test_categorical.py

+21
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,24 @@ def test_categorical_concat_gh7864(self):
202202

203203
dfa = df1.append(df2)
204204
tm.assert_index_equal(df["grade"].cat.categories, dfa["grade"].cat.categories)
205+
206+
def test_categorical_index_upcast(self):
207+
# GH 17629
208+
# test upcasting to object when concatinating on categorical indexes
209+
# with non-identical categories
210+
211+
a = DataFrame({"foo": [1, 2]}, index=Categorical(["foo", "bar"]))
212+
b = DataFrame({"foo": [4, 3]}, index=Categorical(["baz", "bar"]))
213+
214+
res = pd.concat([a, b])
215+
exp = DataFrame({"foo": [1, 2, 4, 3]}, index=["foo", "bar", "baz", "bar"])
216+
217+
tm.assert_equal(res, exp)
218+
219+
a = Series([1, 2], index=Categorical(["foo", "bar"]))
220+
b = Series([4, 3], index=Categorical(["baz", "bar"]))
221+
222+
res = pd.concat([a, b])
223+
exp = Series([1, 2, 4, 3], index=["foo", "bar", "baz", "bar"])
224+
225+
tm.assert_equal(res, exp)

0 commit comments

Comments
 (0)