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: Correct wildcard expansion for functions #19449

Merged
merged 4 commits into from
Oct 26, 2024

Conversation

siddharth-vi
Copy link
Contributor

@siddharth-vi siddharth-vi commented Oct 25, 2024

Fixes #19007
Fixes #18968

Remove INPUT_WILDCARD_EXPANSION for the following functions -

  • list.contains
  • list.count_matches
  • pl.duration

INPUT_WILDCARD_EXPANSION is meant for functions which can have variadic arguments. The above functions have fixed number of arguments, hence this flag should not be set.

Behaviour -
Before

import polars as pl

df = pl.DataFrame({"a": [1], "b": [2]})
df.select(pl.duration(hours=pl.all()).name.keep() )

shape: (1, 1)
┌──────────────┐
│ a            │
│ ---          │
│ duration[μs] │
╞══════════════╡
│ 1h 2m        │
└──────────────┘


df = pl.DataFrame({"a": [[1, 2]], "b": [[3, 4]]})
df.select(pl.all().list.contains(3))

#InvalidOperationError: `is_in` operation not supported for dtype `list[i64]`


df = pl.DataFrame({"a": [[1, 2]], "b": [[3, 4]]})
print(df.select(pl.all().list.count_matches(3)))

#SchemaError: could not evaluate comparison between series 'a' of dtype: i64 and series '' of dtype: list[i64]


After

df = pl.DataFrame({"a": [1], "b": [2]})
print(df.select(pl.duration(hours=pl.all()).name.keep() ))

shape: (1, 2)
┌──────────────┬──────────────┐
│ a            ┆ b            │
│ ---          ┆ ---          │
│ duration[μs] ┆ duration[μs] │
╞══════════════╪══════════════╡
│ 1h           ┆ 2h           │
└──────────────┴──────────────┘

df = pl.DataFrame({"a": [[1, 2]], "b": [[3, 4]]})
df.select(pl.all().list.contains(3))

shape: (1, 2)
┌───────┬──────┐
│ a     ┆ b    │
│ ---   ┆ ---  │
│ bool  ┆ bool │
╞═══════╪══════╡
│ false ┆ true │
└───────┴──────┘

df = pl.DataFrame({"a": [[1, 2]], "b": [[3, 4]]})
print(df.select(pl.all().list.count_matches(3)))

shape: (1, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ u32 ┆ u32 │
╞═════╪═════╡
│ 0   ┆ 1   │
└─────┴─────┘

More discussion about this can be found in the issue #19007

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

codecov bot commented Oct 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.94%. Comparing base (f01fb7b) to head (fbc82a2).
Report is 11 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #19449       +/-   ##
===========================================
+ Coverage   60.05%   79.94%   +19.89%     
===========================================
  Files        1533     1534        +1     
  Lines      210940   211049      +109     
  Branches     2442     2444        +2     
===========================================
+ Hits       126680   168732    +42052     
+ Misses      83706    41762    -41944     
- Partials      554      555        +1     

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

@ritchie46
Copy link
Member

Thanks, can you add some tests on the python side?

@siddharth-vi
Copy link
Contributor Author

@ritchie46 Please check now.

@ritchie46
Copy link
Member

Thanks!

@ritchie46 ritchie46 merged commit d616866 into pola-rs:main Oct 26, 2024
25 checks passed
@cmdlineluser
Copy link
Contributor

Thank you @siddharth-vi

I'm not sure if it's something you want to look into, but I think there were also some other cases where this seems to happen.

The corresponding .arr.* methods also seemed to demonstrate the same behaviour e.g. .arr.count_matches() etc.

@siddharth-vi
Copy link
Contributor Author

Will check them out @cmdlineluser

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.

pl.duration(days=pl.all()) also passes values to hours= pl.all().list.count_matches results in a SchemaError
3 participants