Skip to content
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

Fix join of MultiIndex to Index with one column and overlapping name. #9830

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,14 +1147,14 @@ def join(
if isinstance(lhs, cudf.MultiIndex):
if level is not None and isinstance(level, int):
on = lhs._data.select_by_index(level).names[0]
right_names = (on,) or right_names
right_names = (on,) if on is not None else right_names
on = right_names[0]
if how == "outer":
how = "left"
elif how == "right":
how = "inner"
else:
# Both are nomal indices
# Both are normal indices
right_names = left_names
on = right_names[0]

Expand Down
13 changes: 13 additions & 0 deletions python/cudf/cudf/tests/test_joining.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,3 +2150,16 @@ def test_join_redundant_params():
lhs.merge(rhs, right_on="a", left_index=True, right_index=True)
with pytest.raises(ValueError):
lhs.merge(rhs, left_on="c", right_on="b")


def test_join_multiindex_index():
# test joining a MultiIndex with an Index with overlapping name
lhs = (
cudf.DataFrame({"a": [2, 3, 1], "b": [3, 4, 2]})
.set_index(["a", "b"])
.index
)
rhs = cudf.DataFrame({"a": [1, 4, 3]}).set_index("a").index
expect = lhs.to_pandas().join(rhs.to_pandas(), how="inner")
got = lhs.join(rhs, how="inner")
assert_join_results_equal(expect, got, how="inner")
bdice marked this conversation as resolved.
Show resolved Hide resolved