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(python): Change default number of rows printed in Notebooks for DataFrame/Series to 10 #14536

Merged
merged 5 commits into from
Feb 26, 2024

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented Feb 16, 2024

Closes #14515

Changes

  • For DataFrames: changed from 25 to 10.
  • For Series: changed from 25 to 20 10 also.
  • Fix display when row limit is an odd number

I guess we could also do 10 rows for both?

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Feb 16, 2024
@JulianCologne
Copy link
Contributor

I guess we could also do 10 rows for both?

imo 10 is nice and would be consistent.

Also might have found another formatting inconsistency: 🤔

df = pl.DataFrame({"a": pl.int_range(0, 100, eager=True)})
ser = df.get_column("a")

image

@stinodego
Copy link
Member Author

stinodego commented Feb 16, 2024

imo 10 is nice and would be consistent.

Let's go for that. Too much vertical scrolling in a Notebook is annoying.

Also might have found another formatting inconsistency: 🤔

There are some off-by-one errors... I think I may address the HTML ones here actually if I have time, otherwise it can be a separate PR.

@stinodego stinodego changed the title feat(python): Change default number of rows printed in Notebooks for DataFrame/Series feat(python): Change default number of rows printed in Notebooks for DataFrame/Series to 10 Feb 16, 2024
Comment on lines +66 to +70
half, rest = divmod(max_rows, 2)
self.row_idx = [
*list(range(max_rows // 2)),
*list(range(half + rest)),
-1,
*list(range(df.height - max_rows // 2, df.height)),
*list(range(df.height - half, df.height)),
Copy link
Member Author

Choose a reason for hiding this comment

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

This makes sure display is correct when the limit is odd - e.g. if the limit is 9, we get 5 rows displayed, then ..., then the last 4 rows.

max_rows = int(os.environ.get("POLARS_FMT_MAX_ROWS", default=25))
max_cols = self.width

max_rows = int(os.environ.get("POLARS_FMT_MAX_ROWS", default=10))
Copy link
Member Author

Choose a reason for hiding this comment

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

Default was changed here from 25 to 10.

@stinodego stinodego added the A-formatting Area: display/repr of Polars objects label Feb 23, 2024
@stinodego stinodego merged commit c00a2bf into main Feb 26, 2024
12 checks passed
@stinodego stinodego deleted the html-rows branch February 26, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-formatting Area: display/repr of Polars objects enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default table rows displayed in Notebooks to 10 (pl.Config.set_tbl_rows(10))
2 participants