Skip to content

Commit

Permalink
TST: Added test for upcasting to object when concatinating on categor…
Browse files Browse the repository at this point in the history
…ical indexes with non-identical categories (#42278)
  • Loading branch information
P-Tillmann authored Jul 1, 2021
1 parent 1d4209d commit 0135b79
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pandas/tests/reshape/concat/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,24 @@ def test_categorical_concat_gh7864(self):

dfa = df1.append(df2)
tm.assert_index_equal(df["grade"].cat.categories, dfa["grade"].cat.categories)

def test_categorical_index_upcast(self):
# GH 17629
# test upcasting to object when concatinating on categorical indexes
# with non-identical categories

a = DataFrame({"foo": [1, 2]}, index=Categorical(["foo", "bar"]))
b = DataFrame({"foo": [4, 3]}, index=Categorical(["baz", "bar"]))

res = pd.concat([a, b])
exp = DataFrame({"foo": [1, 2, 4, 3]}, index=["foo", "bar", "baz", "bar"])

tm.assert_equal(res, exp)

a = Series([1, 2], index=Categorical(["foo", "bar"]))
b = Series([4, 3], index=Categorical(["baz", "bar"]))

res = pd.concat([a, b])
exp = Series([1, 2, 4, 3], index=["foo", "bar", "baz", "bar"])

tm.assert_equal(res, exp)

0 comments on commit 0135b79

Please sign in to comment.