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

Inject a repartition layer for inner merges #335

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
phofl committed Oct 13, 2023
commit 8f41dc6fa7cc2d5d23b99401ead8d147adc11b38
24 changes: 24 additions & 0 deletions dask_expr/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dask.dataframe.utils import assert_eq

from dask_expr import from_pandas
from dask_expr._expr import Projection
from dask_expr.tests._util import _backend_library

# Set DataFrame backend for this module
Expand Down Expand Up @@ -206,3 +207,26 @@ def test_merge_combine_similar(npartitions_left, npartitions_right):
expected["new"] = expected.b + expected.c
expected = expected.groupby(["a", "e", "x"]).new.sum()
assert_eq(query, expected)


def test_merge_combine_similar_intermediate_projections():
pdf = lib.DataFrame(
{
"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"b": 1,
"c": 1,
}
)
pdf2 = lib.DataFrame({"a": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "x": 1})
pdf3 = lib.DataFrame({"b": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "y": 1})

df = from_pandas(pdf, npartitions=2)
df2 = from_pandas(pdf2, npartitions=3)
df3 = from_pandas(pdf3, npartitions=3)

q = df.merge(df2).merge(df3)[["b", "x", "y"]]
result = q.optimize(fuse=False)
# Check that we have intermediate projections dropping unnecessary columns
assert isinstance(result.expr.left, Projection)
assert result.expr.left.operand("columns") == ["b", "x"]
assert_eq(result, pdf.merge(pdf2).merge(pdf3)[["b", "x", "y"]], check_index=False)
Loading