-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Shorter truncated Series/DataFrame repr: introduce min_rows #27095
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
Changes from 8 commits
1361fa4
d62407a
b8f483e
98e7d43
e4b2144
8060faf
41c8543
577f078
577c5cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -588,14 +588,16 @@ def __repr__(self): | |
return buf.getvalue() | ||
|
||
max_rows = get_option("display.max_rows") | ||
min_rows = get_option("display.min_rows") | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. can the logic be added before this call to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although, looking at it more closely, that special case is only if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 it appears from the comments that adding arguments to |
||
max_cols=max_cols, line_width=width, | ||
show_dimensions=show_dimensions) | ||
|
||
return buf.getvalue() | ||
|
||
|
@@ -633,8 +635,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): | ||
max_rows=None, min_rows=None, max_cols=None, | ||
show_dimensions=False, decimal='.', line_width=None): | ||
""" | ||
Render a DataFrame to a console-friendly tabular output. | ||
%(shared_params)s | ||
|
@@ -663,6 +665,7 @@ def to_string(self, buf=None, columns=None, col_space=None, header=True, | |
sparsify=sparsify, justify=justify, | ||
index_names=index_names, | ||
header=header, index=index, | ||
min_rows=min_rows, | ||
max_rows=max_rows, | ||
max_cols=max_cols, | ||
show_dimensions=show_dimensions, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1486,17 +1486,20 @@ def __repr__(self): | |
width, height = get_terminal_size() | ||
max_rows = (height if get_option("display.max_rows") == 0 else | ||
get_option("display.max_rows")) | ||
min_rows = (height if get_option("display.max_rows") == 0 else | ||
get_option("display.min_rows")) | ||
show_dimensions = get_option("display.show_dimensions") | ||
|
||
self.to_string(buf=buf, name=self.name, dtype=self.dtype, | ||
max_rows=max_rows, length=show_dimensions) | ||
min_rows=min_rows, max_rows=max_rows, | ||
length=show_dimensions) | ||
result = buf.getvalue() | ||
|
||
return result | ||
|
||
def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True, | ||
index=True, length=False, dtype=False, name=False, | ||
max_rows=None): | ||
max_rows=None, min_rows=None): | ||
""" | ||
Render a string representation of the Series. | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. in theory should add a versionaded here, but not worth repushing |
||
The number of rows to display in a truncated repr (when number | ||
of rows is above `max_rows`). | ||
|
||
Returns | ||
------- | ||
|
@@ -1533,6 +1539,7 @@ def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True, | |
header=header, index=index, | ||
dtype=dtype, na_rep=na_rep, | ||
float_format=float_format, | ||
min_rows=min_rows, | ||
max_rows=max_rows) | ||
result = formatter.to_string() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
The number of rows to display in the console in a truncated repr | ||
(when number of rows is above `max_rows`). | ||
max_cols : int, optional | ||
Maximum number of columns to display in the console. | ||
show_dimensions : bool, default False | ||
|
@@ -159,7 +162,7 @@ class SeriesFormatter: | |
|
||
def __init__(self, series, buf=None, length=True, header=True, index=True, | ||
na_rep='NaN', name=False, float_format=None, dtype=True, | ||
max_rows=None): | ||
max_rows=None, min_rows=None): | ||
self.series = series | ||
self.buf = buf if buf is not None else StringIO() | ||
self.name = name | ||
|
@@ -168,6 +171,7 @@ def __init__(self, series, buf=None, length=True, header=True, index=True, | |
self.length = length | ||
self.index = index | ||
self.max_rows = max_rows | ||
self.min_rows = min_rows | ||
|
||
if float_format is None: | ||
float_format = get_option("display.float_format") | ||
|
@@ -179,10 +183,17 @@ def __init__(self, series, buf=None, length=True, header=True, index=True, | |
|
||
def _chk_truncate(self): | ||
from pandas.core.reshape.concat import concat | ||
min_rows = self.min_rows | ||
jorisvandenbossche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
max_rows = self.max_rows | ||
# truncation determined by max_rows, actual truncated number of rows | ||
# used below by min_rows | ||
truncate_v = max_rows and (len(self.series) > max_rows) | ||
series = self.series | ||
if truncate_v: | ||
if min_rows: | ||
# if min_rows is set (not None or 0), set max_rows to minimum | ||
# of both | ||
max_rows = min(min_rows, max_rows) | ||
if max_rows == 1: | ||
row_num = max_rows | ||
series = series.iloc[:max_rows] | ||
|
@@ -391,8 +402,8 @@ def __init__(self, frame, buf=None, columns=None, col_space=None, | |
header=True, index=True, na_rep='NaN', formatters=None, | ||
justify=None, float_format=None, sparsify=None, | ||
index_names=True, line_width=None, max_rows=None, | ||
max_cols=None, show_dimensions=False, decimal='.', | ||
table_id=None, render_links=False, **kwds): | ||
min_rows=None, max_cols=None, show_dimensions=False, | ||
decimal='.', table_id=None, render_links=False, **kwds): | ||
self.frame = frame | ||
if buf is not None: | ||
self.buf = _expand_user(_stringify_path(buf)) | ||
|
@@ -414,6 +425,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None, | |
self.index = index | ||
self.line_width = line_width | ||
self.max_rows = max_rows | ||
self.min_rows = min_rows | ||
self.max_cols = max_cols | ||
self.max_rows_displayed = min(max_rows or len(self.frame), | ||
len(self.frame)) | ||
|
@@ -471,6 +483,10 @@ def _chk_truncate(self): | |
max_rows = h | ||
|
||
if not hasattr(self, 'max_rows_adj'): | ||
if max_rows: | ||
if (len(self.frame) > max_rows) and self.min_rows: | ||
# if truncated, set max_rows showed to min_rows | ||
max_rows = min(self.min_rows, max_rows) | ||
self.max_rows_adj = max_rows | ||
if not hasattr(self, 'max_cols_adj'): | ||
self.max_cols_adj = max_cols | ||
|
Uh oh!
There was an error while loading. Please reload this page.