Merge pull request #47 from blaklaybul/trim-display

Tabular Display: show 10 rows if index is larger than max_rows
This commit is contained in:
stevedodson 2019-11-18 10:35:03 +01:00 committed by GitHub
commit c93d07981d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -244,13 +244,22 @@ class DataFrame(NDFrame):
"""
buf = StringIO()
# max_rows and max_cols determine the maximum size of the pretty printed tabular
# representation of the dataframe. pandas defaults are 60 and 20 respectively.
# dataframes where len(df) > max_rows shows a truncated view with 10 rows shown.
max_rows = pd.get_option("display.max_rows")
max_cols = pd.get_option("display.max_columns")
min_rows = pd.get_option("display.min_rows")
if len(self) > max_rows:
max_rows = min_rows
show_dimensions = pd.get_option("display.show_dimensions")
if pd.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)

View File

@ -33,6 +33,18 @@ class TestDataFrameRepr(TestData):
assert pd_head_11_str == ed_head_11_str
def test_less_than_max_rows_to_string(self):
ed_flights = self.ed_flights()
pd_flights = self.pd_flights()
ed_less_than_max = ed_flights[ed_flights['AvgTicketPrice']>1190]
pd_less_than_max = pd_flights[pd_flights['AvgTicketPrice']>1190]
ed_less_than_max_str = ed_less_than_max.to_string()
pd_less_than_max_str = pd_less_than_max.to_string()
assert pd_less_than_max_str == ed_less_than_max_str
def test_repr(self):
ed_ecommerce = self.ed_ecommerce()
pd_ecommerce = self.pd_ecommerce()