Skip to content

Commit b2a26ec

Browse files
authored
TEST: join df with categorical multiIndex (pandas-dev#51088)
* TEST: join df with categorical multiIndex * compare result and expected DataFrame * add pytest.mark.parameterize to the test * use dataframes from the original example
1 parent 82ccccd commit b2a26ec

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

pandas/tests/reshape/merge/test_join.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,43 @@ def test_join_empty(left_empty, how, exp):
956956
expected = expected.rename_axis("A")
957957

958958
tm.assert_frame_equal(result, expected)
959+
960+
961+
@pytest.mark.parametrize(
962+
"how, values",
963+
[
964+
("inner", [0, 1, 2]),
965+
("outer", [0, 1, 2]),
966+
("left", [0, 1, 2]),
967+
("right", [0, 2, 1]),
968+
],
969+
)
970+
def test_join_multiindex_categorical_output_index_dtype(how, values):
971+
# GH#50906
972+
df1 = DataFrame(
973+
{
974+
"a": Categorical([0, 1, 2]),
975+
"b": Categorical([0, 1, 2]),
976+
"c": [0, 1, 2],
977+
}
978+
).set_index(["a", "b"])
979+
980+
df2 = DataFrame(
981+
{
982+
"a": Categorical([0, 2, 1]),
983+
"b": Categorical([0, 2, 1]),
984+
"d": [0, 2, 1],
985+
}
986+
).set_index(["a", "b"])
987+
988+
expected = DataFrame(
989+
{
990+
"a": Categorical(values),
991+
"b": Categorical(values),
992+
"c": values,
993+
"d": values,
994+
}
995+
).set_index(["a", "b"])
996+
997+
result = df1.join(df2, how=how)
998+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)