-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: Struct filter by index #18778
fix: Struct filter by index #18778
Conversation
Thanks @barak1412 I think negative indexing is normally allowed: >>> df.with_columns(a = pl.col.foo.struct[-1])
# shape: (2, 2)
# ┌───────────┬─────┐
# │ foo ┆ a │
# │ --- ┆ --- │
# │ struct[1] ┆ i64 │
# ╞═══════════╪═════╡
# │ {1} ┆ 1 │
# │ {2} ┆ 2 │
# └───────────┴─────┘ The logic for that seems to be here: polars/crates/polars-plan/src/dsl/function_expr/struct_.rs Lines 26 to 27 in 6561eba
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #18778 +/- ##
==========================================
+ Coverage 79.84% 79.86% +0.02%
==========================================
Files 1518 1518
Lines 205576 205637 +61
Branches 2892 2893 +1
==========================================
+ Hits 164132 164238 +106
+ Misses 40896 40851 -45
Partials 548 548 ☔ View full report in Codecov by Sentry. |
@cmdlineluser Sure I will look into it. |
@cmdlineluser Fixed |
I appreciate the fix, but this isn't how it should be fixed. The expression should be replaced by a field by name, hence the panic. We should never access data by index as that doesn't allow us to remove fields we don't need. |
@ritchie46 Sure, I am glad to learn So the right way is given index, fetch the right field and then use its name to fetch the data in the expression level? |
Yes, but we already have that logic, it seems that we don't hit that in the Note that df = pl.DataFrame({"foo": [{"a":1},{"a":2}]})
df.select(pl.col.foo.struct[0] == 1) I think you should look into |
Thanks for the guidance, should be the right fix now. |
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.
Thanks @barak1412. That's the proper fix.
Fixes #18732.