Skip to content

Commit 527bfc5

Browse files
authored
TST: Add test for concat multiindex with category (#54103)
Add test for concat multiindex with category
1 parent 9ff3322 commit 527bfc5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pandas/tests/reshape/concat/test_concat.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,3 +832,32 @@ def test_concat_mismatched_keys_length():
832832
concat((x for x in sers), keys=(y for y in keys), axis=1)
833833
with tm.assert_produces_warning(FutureWarning, match=msg):
834834
concat((x for x in sers), keys=(y for y in keys), axis=0)
835+
836+
837+
def test_concat_multiindex_with_category():
838+
df1 = DataFrame(
839+
{
840+
"c1": Series(list("abc"), dtype="category"),
841+
"c2": Series(list("eee"), dtype="category"),
842+
"i2": Series([1, 2, 3]),
843+
}
844+
)
845+
df1 = df1.set_index(["c1", "c2"])
846+
df2 = DataFrame(
847+
{
848+
"c1": Series(list("abc"), dtype="category"),
849+
"c2": Series(list("eee"), dtype="category"),
850+
"i2": Series([4, 5, 6]),
851+
}
852+
)
853+
df2 = df2.set_index(["c1", "c2"])
854+
result = concat([df1, df2])
855+
expected = DataFrame(
856+
{
857+
"c1": Series(list("abcabc"), dtype="category"),
858+
"c2": Series(list("eeeeee"), dtype="category"),
859+
"i2": Series([1, 2, 3, 4, 5, 6]),
860+
}
861+
)
862+
expected = expected.set_index(["c1", "c2"])
863+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)