-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Shorter truncated Series/DataFrame repr: introduce min_rows #27095
Conversation
pandas/core/frame.py
Outdated
@@ -665,8 +667,8 @@ def _repr_html_(self): | |||
def to_string(self, buf=None, columns=None, col_space=None, header=True, | |||
index=True, na_rep='NaN', formatters=None, float_format=None, | |||
sparsify=None, index_names=True, justify=None, | |||
max_rows=None, max_cols=None, show_dimensions=False, | |||
decimal='.', line_width=None): | |||
min_rows=None, max_rows=None, max_cols=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add types on new args (and old ones if you can)
@jorisvandenbossche think you'll be able to update in the next 24 hours? |
Codecov Report
@@ Coverage Diff @@
## master #27095 +/- ##
===========================================
- Coverage 91.79% 41.89% -49.91%
===========================================
Files 180 180
Lines 50934 50803 -131
===========================================
- Hits 46757 21286 -25471
- Misses 4177 29517 +25340
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #27095 +/- ##
===========================================
- Coverage 91.79% 41.89% -49.91%
===========================================
Files 180 180
Lines 50934 50803 -131
===========================================
- Hits 46757 21286 -25471
- Misses 4177 29517 +25340
Continue to review full report at Codecov.
|
I added some tests. Further to do:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 on adding keywords to public methods. see #27000 (comment)
max_cols = get_option("display.max_columns") | ||
show_dimensions = get_option("display.show_dimensions") | ||
if get_option("display.expand_frame_repr"): | ||
width, _ = console.get_console_size() | ||
else: | ||
width = None | ||
self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols, | ||
line_width=width, show_dimensions=show_dimensions) | ||
self.to_string(buf=buf, max_rows=max_rows, min_rows=min_rows, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can the logic be added before this call to .to_string
(isn't it as simple as just set max_rows to min_rows if len(self.frame) > max_rows?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the simple cases, yes. And I agree that could be a nice option. But there are some corner cases that are only handled within the DataFrameFormatter
class (eg if max_rows = 0, we check the terminal size)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, looking at it more closely, that special case is only if max_rows
is 0 or None, so that could be easily checked. So yes, this would in principle be possible (and probably even give easier code). But that means that we move some of the logic of the repr out of the Formatter class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that means that we move some of the logic of the repr out of the Formatter class.
i agree. but this logic is related to display options. i'd prefer to see all the display option handling removed from the Formatter classes entirely and only appear in __repr__
and _repr_html_
it appears from the comments that adding arguments to to_string
is not considered undesirable. so this topic can be addressed another day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. A release note would be nice if you have a chance.
-1 on adding keywords to public methods. see #27000 (comment)
I don't have a strong opinion here, but I can see them being useful.
pandas/io/formats/format.py
Outdated
max_rows = self.max_rows | ||
# if min_rows is None, follow value of max_rows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None or 0
As I said above, it is easy to avoid that, if we want (with only a little bit of code duplication, just a call to the |
I like the consistency argument here, +1 on adding min_rows to to_string |
@jorisvandenbossche doc failure: https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=13946&view=logs&jobId=7e620c85-24a8-5ffa-8b1f-642bc9b1fc36&taskId=2febcae8-7f6a-51bb-45aa-d6e72c9ea7e2&lineStart=2268&lineEnd=2269&colStart=1&colEnd=1
|
Ah, this annoying check we have in our CI ;-) |
@@ -1522,6 +1525,9 @@ def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True, | |||
max_rows : int, optional | |||
Maximum number of rows to show before truncating. If None, show | |||
all. | |||
min_rows : int, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory should add a versionaded here, but not worth repushing
@@ -79,6 +79,9 @@ | |||
* unset. | |||
max_rows : int, optional | |||
Maximum number of rows to display in the console. | |||
min_rows : int, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
this is green. any objections? |
very nice @jorisvandenbossche |
Closes #27000
(didn't yet add tests, docs or whatsnew, but I think the implementation is already more or less complete)