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: Improve error messages in context stack #15881

Merged
merged 2 commits into from
Apr 25, 2024
Merged

feat: Improve error messages in context stack #15881

merged 2 commits into from
Apr 25, 2024

Conversation

ritchie46
Copy link
Member

@ritchie46 ritchie46 commented Apr 25, 2024

Single context

Ignore the context:

>>> s = pl.DataFrame({"a": [1, 2], "b": [3, 4]}).to_struct()
>>> s.struct.field("c")
---------------------------------------------------------------------------
StructFieldNotFoundError                  Traceback (most recent call last)
Cell In[3], line 3
      1 s = pl.DataFrame({"a": [1, 2], "b": [3, 4]}).to_struct()
----> 3 s.struct.field("c")

File ~/code/polars/py-polars/polars/series/utils.py:107, in call_expr.<locals>.wrapper(self, *args, **kwargs)
    105     expr = getattr(expr, namespace)
    106 f = getattr(expr, func.__name__)
--> 107 return s.to_frame().select_seq(f(*args, **kwargs)).to_series()

File ~/code/polars/py-polars/polars/dataframe/frame.py:7915, in DataFrame.select_seq(self, *exprs, **named_exprs)
   7892 def select_seq(
   7893     self, *exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr
   7894 ) -> DataFrame:
   7895     """
   7896     Select columns from this DataFrame.
   7897 
   (...)
   7913     select
   7914     """
-> 7915     return self.lazy().select_seq(*exprs, **named_exprs).collect(_eager=True)

File ~/code/polars/py-polars/polars/lazyframe/frame.py:1811, in LazyFrame.collect(self, type_coercion, predicate_pushdown, projection_pushdown, simplify_expression, slice_pushdown, comm_subplan_elim, comm_subexpr_elim, no_optimization, streaming, background, _eager)
   1808 if background:
   1809     return InProcessQuery(ldf.collect_concurrently())
-> 1811 return wrap_df(ldf.collect())

StructFieldNotFoundError: c

Context stack

>>>(
...    pl.scan_csv("does not exist")
...    .filter(pl.col("a") == 3)
...    .explode("bar")
...    .select(pl.col("foo"))
...    .collect()
...)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[4], line 6
      1 (
      2     pl.scan_csv("does not exist")
      3     .filter(pl.col("a") == 3)
      4     .explode("bar")
      5     .select(pl.col("foo"))
----> 6     .collect()
      7 )

File ~/code/polars/py-polars/polars/lazyframe/frame.py:1811, in LazyFrame.collect(self, type_coercion, predicate_pushdown, projection_pushdown, simplify_expression, slice_pushdown, comm_subplan_elim, comm_subexpr_elim, no_optimization, streaming, background, _eager)
   1808 if background:
   1809     return InProcessQuery(ldf.collect_concurrently())
-> 1811 return wrap_df(ldf.collect())

FileNotFoundError: No such file or directory (os error 2): does not exist:

This error occurred with the following context stack:
	[1] 'csv scan' failed
	[2] 'filter' input failed to resolve
	[3] 'explode' input failed to resolve
	[4] 'select' input failed to resolve

closes #15880

@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 Apr 25, 2024
@stinodego stinodego linked an issue Apr 25, 2024 that may be closed by this pull request
Co-authored-by: Stijn de Gooijer <stijndegooijer@gmail.com>
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix!

@ritchie46 ritchie46 merged commit 44aab96 into main Apr 25, 2024
20 checks passed
@ritchie46 ritchie46 deleted the msg branch April 25, 2024 08:07
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.

New error message format is cryptic in certain circumstances
2 participants