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: Add POLARS_BACKTRACE_IN_ERR for debugging #18333

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

orlp
Copy link
Collaborator

@orlp orlp commented Aug 23, 2024

You can now specify POLARS_BACKTRACE_IN_ERR=1 to include a Rust backtrace inside errors to see where they get created:

>>> import polars as pl
>>> df = pl.DataFrame({"x": [1]})
>>> df.select(pl.col.y)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/orlp/programming/rust/polars/py-polars/polars/dataframe/frame.py", line 8853, in select
    return self.lazy().select(*exprs, **named_exprs).collect(_eager=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/orlp/programming/rust/polars/py-polars/polars/lazyframe/frame.py", line 2034, in collect
    return wrap_df(ldf.collect(callback))
                   ^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ColumnNotFoundError: y

Rust backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/std/src/backtrace.rs:331:13
   3: <polars_error::ErrString as core::convert::From<T>>::from
             at /Users/orlp/programming/rust/polars/crates/polars-error/src/lib.rs:49:17
   4: <T as core::convert::Into<U>>::into
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/core/src/convert/mod.rs:759:9
   5: polars_plan::plans::aexpr::schema::<impl polars_plan::plans::aexpr::AExpr>::to_field_impl::{{closure}}::{{closure}}
             at /Users/orlp/programming/rust/polars/crates/polars-plan/src/plans/aexpr/schema.rs:78:60
...

One caveat: we now cache POLARS_PANIC_ON_ERR which already existed the first time we create an error object. So it's no longer supported to update that dynamically through os.environ.

@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 Aug 23, 2024
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 46.66667% with 8 lines in your changes missing coverage. Please review.

Project coverage is 80.42%. Comparing base (cdc741d) to head (326400c).
Report is 16 commits behind head on main.

Files Patch % Lines
crates/polars-error/src/lib.rs 46.66% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18333      +/-   ##
==========================================
- Coverage   80.48%   80.42%   -0.06%     
==========================================
  Files        1501     1492       -9     
  Lines      199457   198655     -802     
  Branches     2837     2837              
==========================================
- Hits       160541   159777     -764     
+ Misses      38390    38352      -38     
  Partials      526      526              

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

@ritchie46 ritchie46 merged commit 380db32 into pola-rs:main Aug 23, 2024
21 checks passed
@c-peters c-peters added the accepted Ready for implementation label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants