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: Properly broadcast list arithmetic #18858

Closed
wants to merge 3 commits into from

Conversation

cmdlineluser
Copy link
Contributor

ref: #18831

It seems like I just needed to copy the broadcast_array() impl from #18851

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Sep 23, 2024
Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.

Project coverage is 79.89%. Comparing base (262f7bc) to head (bc8029e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...polars-core/src/series/arithmetic/list_borrowed.rs 86.95% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18858      +/-   ##
==========================================
+ Coverage   79.87%   79.89%   +0.02%     
==========================================
  Files        1519     1519              
  Lines      205839   205852      +13     
  Branches     2898     2898              
==========================================
+ Hits       164416   164475      +59     
+ Misses      40875    40829      -46     
  Partials      548      548              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -688,16 +688,6 @@ def test_list_arithmetic_nulls(a: list[Any], b: list[Any], expected: list[Any])


def test_list_arithmetic_error_cases() -> None:
# Different series length:
Copy link
Contributor

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.)

Copy link
Contributor

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.

import polars as pl


def test_literal_broadcast_list() -> None:
Copy link
Contributor

@itamarst itamarst Sep 23, 2024

Choose a reason for hiding this comment

The 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. df.get_column("A") + lit, it sometimes hits different code paths for each when doing arithmetic, so you get different bugs.

I would also suggest adding a test where the literal is a different type than the list, e.g. a Int64, and again testing both lazy and eager (casting definitely works differently).

@cmdlineluser
Copy link
Contributor Author

Thank you @itamarst

I made a naive copy of the broadcast_array() PR as I thought it would be in time for 1.8 to have it working for both array and list.

I will close this as you are working this area already.

@itamarst
Copy link
Contributor

I'm not working on the same thing though, so other than merge conflicts this seems worth continuing.

@itamarst
Copy link
Contributor

But if you don't want to finish it, I can finish it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants