-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: Properly broadcast list arithmetic #18858
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import polars as pl | ||
|
||
|
||
def test_literal_broadcast_list() -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also test eager operations in addition to lazy operations, e.g. I would also suggest adding a test where the literal is a different type than the list, e.g. a |
||
df = pl.DataFrame({"A": [[0.1, 0.2], [0.3, 0.4]]}) | ||
|
||
lit = pl.lit([3.0, 5.0]) | ||
assert df.select( | ||
mul=pl.all() * lit, | ||
div=pl.all() / lit, | ||
add=pl.all() + lit, | ||
sub=pl.all() - lit, | ||
div_=lit / pl.all(), | ||
add_=lit + pl.all(), | ||
sub_=lit - pl.all(), | ||
mul_=lit * pl.all(), | ||
).to_dict(as_series=False) == { | ||
"mul": [[0.30000000000000004, 1.0], [0.8999999999999999, 2.0]], | ||
"div": [[0.03333333333333333, 0.04], [0.09999999999999999, 0.08]], | ||
"add": [[3.1, 5.2], [3.3, 5.4]], | ||
"sub": [[-2.9, -4.8], [-2.7, -4.6]], | ||
"div_": [[30.0, 25.0], [10.0, 12.5]], | ||
"add_": [[3.1, 5.2], [3.3, 5.4]], | ||
"sub_": [[2.9, 4.8], [2.7, 4.6]], | ||
"mul_": [[0.30000000000000004, 1.0], [0.8999999999999999, 2.0]], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think some of these tests are necessary? E.g.
pl.Series([[1, 2], [3, 4]]) + pl.Series([[1, 1], [2, 2], [3, 4]])
should complain.(Separately I am honestly not super-excited about semantics of single-item Series working this way, but I guess that's how literals work? So if that design decision has already been made, oh well.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or rather, some variations of existing tests should still be there, by tweaking existing assertions instead of deleting them.