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 binops with one partition #1143

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions dask_expr/_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,9 @@ def _divisions(self):
else:
return super()._divisions()

def _broadcast_dep(self, dep: Expr):
return dep.npartitions == 1


class Add(Binop):
operation = operator.add
Expand Down
29 changes: 29 additions & 0 deletions dask_expr/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2674,3 +2674,32 @@ def test_to_backend_simplify():
assert str(df2.expr) != str(df[["y"]].expr)
df3 = df2.simplify()
assert str(df3.expr) == str(df[["y"]].expr)


def test_add_different_index_one_partition():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this test passes for me on main - Is that expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a good chance that #1150 fixed this

pdf1 = pd.DataFrame(
{
"prediction_probability": [1.0] * 2,
"prediction": [1, 1],
"num_runs": [1, 1],
"Idx": [1, 4],
}
).set_index("Idx")

pdf2 = pd.DataFrame(
{
"prediction_probability": [1.0] * 2,
"prediction": [1, 1],
"num_runs": [
1,
1,
],
"Idx": [1, 4],
}
).set_index("Idx")

df1 = from_pandas(pdf1)
df2 = from_pandas(pdf2)
df1["prediction"] = df1.prediction.add(df2.prediction, fill_value=0)
pdf1["prediction"] = pdf1.prediction.add(pdf2.prediction, fill_value=0)
assert_eq(df1, pdf1)
Loading