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

feat: Raise informative error on Unknown unnest #19830

Merged
merged 2 commits into from
Nov 17, 2024
Merged

feat: Raise informative error on Unknown unnest #19830

merged 2 commits into from
Nov 17, 2024

Conversation

ritchie46
Copy link
Member

closes #19812

>>> df = pl.DataFrame({"a": [[1, 2, 3]]})
>>> df.select(pl.col("a").list.to_struct().struct.unnest()
---------------------------------------------------------------------------
InvalidOperationError                     Traceback (most recent call last)
Cell In[3], line 2
     1 df = pl.DataFrame({"a": [[1, 2, 3]]})
----> 2 df.select(pl.col("a").list.to_struct().struct.unnest())

File ~/code/polars/py-polars/polars/dataframe/frame.py:9029, in DataFrame.select(self, *exprs, **named_exprs)
  8929 def select(
  8930     self, *exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr
  8931 ) -> DataFrame:
  8932     """
  8933     Select columns from this DataFrame.
  8934 
  (...)
  9027     └──────────────┘
  9028     """
-> 9029     return self.lazy().select(*exprs, **named_exprs).collect(_eager=True)

File ~/code/polars/py-polars/polars/lazyframe/frame.py:2029, in LazyFrame.collect(self, type_coercion, predicate_pushdown, projection_pushdown, simplify_expression, slice_pushdown, comm_subplan_elim, comm_subexpr_elim, cluster_with_columns, collapse_joins, no_optimization, streaming, engine, background, _eager, **_kwargs)
  2027 # Only for testing purposes
  2028 callback = _kwargs.get("post_opt_callback", callback)
-> 2029 return wrap_df(ldf.collect(callback))

InvalidOperationError: expected 'struct' got an unknown data type

This means there was an operation of which the output data type could not be determined statically.
Try setting the output data type for that operation.

Hint: set 'upper_bound' for 'list.to_struct'.

Resolved plan until failure:

   ---> FAILED HERE RESOLVING 'select' <---
DF ["a"]; PROJECT */1 COLUMNS; SELECTION: None

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Nov 17, 2024
Copy link

codecov bot commented Nov 17, 2024

Codecov Report

Attention: Patch coverage is 8.33333% with 22 lines in your changes missing coverage. Please review.

Project coverage is 79.33%. Comparing base (245d549) to head (fa982fe).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...polars-plan/src/plans/conversion/expr_expansion.rs 8.33% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19830      +/-   ##
==========================================
- Coverage   79.33%   79.33%   -0.01%     
==========================================
  Files        1548     1548              
  Lines      214193   214215      +22     
  Branches     2460     2460              
==========================================
  Hits       169937   169937              
- Misses      43698    43720      +22     
  Partials      558      558              

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

@ritchie46 ritchie46 merged commit da38e37 into main Nov 17, 2024
24 checks passed
@ritchie46 ritchie46 deleted the err branch November 17, 2024 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

list.to_struct().struct.unnest() fails
1 participant