Skip to content

TEST: join df with categorical multiIndex #51088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pandas/tests/reshape/merge/test_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,3 +956,43 @@ def test_join_empty(left_empty, how, exp):
expected = expected.rename_axis("A")

tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"how, values",
[
("inner", [0, 1, 2]),
("outer", [0, 1, 2]),
("left", [0, 1, 2]),
("right", [0, 2, 1]),
],
)
def test_join_multiindex_categorical_output_index_dtype(how, values):
# GH#50906
df1 = DataFrame(
{
"a": Categorical([0, 1, 2]),
"b": Categorical([0, 1, 2]),
"c": [0, 1, 2],
}
).set_index(["a", "b"])

df2 = DataFrame(
{
"a": Categorical([0, 2, 1]),
"b": Categorical([0, 2, 1]),
"d": [0, 2, 1],
}
).set_index(["a", "b"])

expected = DataFrame(
{
"a": Categorical(values),
"b": Categorical(values),
"c": values,
"d": values,
}
).set_index(["a", "b"])

result = df1.join(df2, how=how)
tm.assert_frame_equal(result, expected)