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: Fix set_tbl_width_chars panicking with negative width #20906

Merged
merged 5 commits into from
Feb 1, 2025

Conversation

lukemanley
Copy link
Contributor

fixes #18386

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

codecov bot commented Jan 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.30%. Comparing base (6a3fc59) to head (9d51089).
Report is 48 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20906      +/-   ##
==========================================
- Coverage   79.30%   79.30%   -0.01%     
==========================================
  Files        1578     1578              
  Lines      224135   224138       +3     
  Branches     2574     2574              
==========================================
- Hits       177751   177748       -3     
- Misses      45793    45799       +6     
  Partials      591      591              

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

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Jan 25, 2025

Should also be a similar check down in the Rust layer (on read)? 👍
(Since the caller could set the env var there too, or otherwise outside of Config).

@lukemanley lukemanley requested a review from orlp as a code owner January 26, 2025 14:13
@lukemanley
Copy link
Contributor Author

Should also be a similar check down in the Rust layer (on read)? 👍 (Since the caller could set the env var there too, or otherwise outside of Config).

I actually updated the PR this to interpret -1 as no limit (on the rust side) as is done in other config settings. Let me know if you think is ok?

Copy link

codspeed-hq bot commented Jan 26, 2025

CodSpeed Performance Report

Merging #20906 will not alter performance

Comparing lukemanley:set-tbl-width-chars (9d51089) with main (6a3fc59)

Summary

✅ 41 untouched benchmarks

@alexander-beedie
Copy link
Collaborator

I forget if we interpret any negative limit as "no limit" (which I always found a bit weird, as why would -7 mean "no limit" 😄), or if it's just -1? Either way, I agree that making things consistent seems like a good approach.

@lukemanley
Copy link
Contributor Author

I forget if we interpret any negative limit as "no limit" (which I always found a bit weird, as why would -7 mean "no limit" 😄), or if it's just -1? Either way, I agree that making things consistent seems like a good approach.

it looks like other config settings interpret any negative value as "no limit", e.g. here is number of columns displayed:

import polars as pl

df = pl.DataFrame(
    {str(i): [i] for i in range(10)}
)

print(df)

with pl.Config(tbl_cols=-7):
    print(df)
shape: (1, 10)
┌─────┬─────┬─────┬─────┬───┬─────┬─────┬─────┬─────┐
│ 0   ┆ 1   ┆ 2   ┆ 3   ┆ … ┆ 6   ┆ 7   ┆ 8   ┆ 9   │
│ --- ┆ --- ┆ --- ┆ --- ┆   ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆   ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╪═════╪═══╪═════╪═════╪═════╪═════╡
│ 0   ┆ 1   ┆ 2   ┆ 3   ┆ … ┆ 6   ┆ 7   ┆ 8   ┆ 9   │
└─────┴─────┴─────┴─────┴───┴─────┴─────┴─────┴─────┘
>>> with pl.Config(tbl_cols=-7):
...     print(df)
... 
shape: (1, 10)
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ 0   ┆ 1   ┆ 2   ┆ 3   ┆ 4   ┆ 5   ┆ 6   ┆ 7   ┆ 8   ┆ 9   │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞═════╪═════╪═════╪═════╪═════╪═════╪═════╪═════╪═════╪═════╡
│ 0   ┆ 1   ┆ 2   ┆ 3   ┆ 4   ┆ 5   ┆ 6   ┆ 7   ┆ 8   ┆ 9   │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

I just pushed an update to the docstring to make it consisent with other settings, e.g set_tbl_cols: https://docs.pola.rs/api/python/dev/reference/api/polars.Config.set_tbl_cols.html

@ritchie46 ritchie46 merged commit da7decc into pola-rs:main Feb 1, 2025
28 checks passed
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.

PanicException when printing df with Config set_tbl_width_chars(-1)
3 participants