We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 47bb52f commit a264619Copy full SHA for a264619
pandas/tests/reshape/concat/test_categorical.py
@@ -202,3 +202,24 @@ def test_categorical_concat_gh7864(self):
202
203
dfa = df1.append(df2)
204
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
223
+ exp = Series([1, 2, 4, 3], index=["foo", "bar", "baz", "bar"])
224
225
0 commit comments