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(rust,python): Improve printing controls of DataFrame and Series #5047

Merged
merged 1 commit into from
Oct 1, 2022

Conversation

slonik-az
Copy link
Contributor

@slonik-az slonik-az commented Sep 30, 2022

fixes #5046

(1) Let polars.Config.set_tbl_rows to control maximum number of
elements when printing Series (in general any Series => str conversion).
Works the same way as when printing DataFrame.

(2) Calling polars.Config.set_tbl_rows or polars.Config.set_tbl_cols with
any negative integer (-1 is recommended) will cause all the rows
(DataFrame and Series) or all the columns (DataFrame) be printed.

@github-actions github-actions bot added python Related to Python Polars rust Related to Rust Polars labels Sep 30, 2022
@alexander-beedie
Copy link
Collaborator

Nice! Do you think you could tweak the "all rows" value to -1, rather than 0? If I went into a shop and asked for zero apples, I'd be quite surprised if they then gave me all of the apples they had 😄

(On a more realistic note, I can imagine that there may be some --admittedly odd!-- edge-cases where you might actually want to return tables with no rows; overriding zero to mean "all" leaves no way to do so).

@slonik-az
Copy link
Contributor Author

Nice! Do you think you could tweak the "all rows" value to -1, rather than 0?

Fair enough. For the sake of consistency I will make setting rows (cols) to any negative number (-1,-2,etc) to print all the rows (cols) in a DataFrame or Series.

@stinodego stinodego changed the title fix[rust,python]: make Config.set_tbl_rows control printing Series too. fix(rust,python): Make Config.set_tbl_rows control printing Series too. Oct 1, 2022
@github-actions github-actions bot added the fix Bug fix label Oct 1, 2022
fixes pola-rs#5046

(1) Let polars.Config.set_tbl_rows to control maximum number of
    elements when printing Series (in general any Series => str conversion).
    Works the same way as when printing DataFrame.

(2) Calling polars.Config.set_tbl_rows or polars.Config.set_tbl_cols with
    any negative integer (-1 is recommended) will cause all the rows
    (DataFrame and Series) or all the columns (DataFrame) be printed.
@slonik-az
Copy link
Contributor Author

slonik-az commented Oct 1, 2022

(On a more realistic note, I can imagine that there may be some --admittedly odd!-- edge-cases where you might actually want to return tables with no rows; overriding zero to mean "all" leaves no way to do so).

Actually, in the current polars (as of py-0.14.15) when you set_tbl_rows(0) the actual value used for max rows will be 2, making it impossible to force print zero number of rows. In my PR I keep this existing behavior unchanged.

if max_n_rows < 2 {
2
} else {
max_n_rows
}

@slonik-az slonik-az changed the title fix(rust,python): Make Config.set_tbl_rows control printing Series too. fix(rust,python): improve printing controls of DataFrame and Series Oct 1, 2022
@slonik-az
Copy link
Contributor Author

slonik-az commented Oct 1, 2022

Just updated the PR with the requested changes. While at that I squashed all the commits into one and rebased it onto the latest master.

@ritchie46
Copy link
Member

Al right. Thanks!

@ritchie46 ritchie46 merged commit bbc3e17 into pola-rs:master Oct 1, 2022
@stinodego stinodego changed the title fix(rust,python): improve printing controls of DataFrame and Series fix(rust,python): Improve printing controls of DataFrame and Series Oct 1, 2022
@slonik-az
Copy link
Contributor Author

@ritchie46: Thanks for promptly merging it in!

@alexander-beedie
Copy link
Collaborator

Actually, in the current polars (as of py-0.14.15) when you set_tbl_rows(0) the actual value used for max rows will be 2, making it impossible to force print zero number of rows. In my PR I keep this existing behavior unchanged.

if max_n_rows < 2 {
2
} else {
max_n_rows
}

Very peculiar :)
Think I might take a look at this separately later to see why; thanks!

@slonik-az slonik-az mentioned this pull request Feb 13, 2023
2 tasks
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.

printing any Series is limited to 25 elements maximum
3 participants