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

glimpse() fails for lengthy column names #8273

Closed
2 tasks done
CodeCox opened this issue Apr 16, 2023 · 1 comment · Fixed by #8281
Closed
2 tasks done

glimpse() fails for lengthy column names #8273

CodeCox opened this issue Apr 16, 2023 · 1 comment · Fixed by #8281
Assignees
Labels
bug Something isn't working python Related to Python Polars

Comments

@CodeCox
Copy link

CodeCox commented Apr 16, 2023

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

glimpse() fails for lengthy column names

The error msg ValueError: Sign not allowed in string format specifier suggests that a number in the justifiy format string may be negative?

This line of code in frame.py might be the cause of the negative number?

 # limit the amount of data printed such that total width is fixed
        max_col_values = 100 - max_col_name - max_col_dtype

Reproducible example

colc = 'a' * 96
df = pl.DataFrame({colc: [11,22,33]})
df.glimpse()

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[97], line 3
      1 colc = 'a' * 96
      2 df = pl.DataFrame({colc: [11,22,33]})
----> 3 df.glimpse()

File ~\mambaforge\envs\bears\Lib\site-packages\polars\dataframe\frame.py:3577, in DataFrame.glimpse(self, return_as_string)
   3574 # print individual columns: one row per column
   3575 for col_name, dtype_str, val_str in data:
   3576     output.write(
-> 3577         f"$ {col_name:<{max_col_name}}"
   3578         f" {dtype_str:>{max_col_dtype}}"
   3579         f" {val_str:<{min(len(val_str), max_col_values)}}\n"
   3580     )
   3582 s = output.getvalue()
   3584 if not return_as_string:

ValueError: Sign not allowed in string format specifier

Expected behavior

same as this but with len() > 95, and of course use of the "..." in the column name as a 'truncation' to cater for width limit would be preferred to a failure!

colc = 'a' * 95
df = pl.DataFrame({colc: [11,22,33]})
df.glimpse()
Rows: 3
Columns: 1
$ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa <i64> 11, 22, 33

Installed versions

Polars: 0.17.3
@CodeCox CodeCox added bug Something isn't working python Related to Python Polars labels Apr 16, 2023
@zundertj zundertj self-assigned this Apr 16, 2023
@zundertj
Copy link
Collaborator

Thank you for reporting, I have fixed this in #8281.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants