Skip to content

Commit

Permalink
Fix result index of merge (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Aug 13, 2024
1 parent f9ffcb0 commit 2b8f765
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dask_expr/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5703,7 +5703,7 @@ def merge(
if left_on and right_on:
warn_dtype_mismatch(left, right, left_on, right_on)

return new_collection(
result = new_collection(
Merge(
left,
right,
Expand All @@ -5719,6 +5719,10 @@ def merge(
broadcast=broadcast,
)
)
if left._meta.index.name != right._meta.index.name:
return result.rename_axis(index=result._meta.index.name)
else:
return result


@wraps(pd.merge_asof)
Expand Down
16 changes: 16 additions & 0 deletions dask_expr/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,22 @@ def test_merge_avoid_overeager_filter_pushdown():
assert isinstance(result.expr.frame.frame, Merge)


def test_join_consistent_index_names():
pdf1 = pd.DataFrame(index=["a", "b", "c"], data=dict(a=[1, 2, 3]))
pdf1.index.name = "test"
df1 = from_pandas(pdf1, 2)

pdf2 = pd.DataFrame(index=["a", "b", "d"], data=dict(b=[1, 2, 3]))
df2 = from_pandas(pdf2, 2)
result = df1.join(df2, how="outer")
expected = pdf1.join(pdf2, how="outer")
assert_eq(result, expected, check_index=False)
assert result.index.name is None
assert result._meta.index.name is None
assert result.partitions[0].compute().index.name is None
assert expected.index.name is None


@pytest.mark.parametrize("how", ["left", "inner", "right", "outer"])
def test_isin_filter_pushdown(how):
pdf1 = pd.DataFrame(
Expand Down

0 comments on commit 2b8f765

Please sign in to comment.