implements min rows to truncate display for large results

This commit is contained in:
Michael Hirsch 2019-11-15 17:38:46 -05:00
parent b0be68e1db
commit 30d307bdaf
2 changed files with 19 additions and 5 deletions

View File

@ -244,8 +244,16 @@ 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()
@ -588,10 +596,6 @@ class DataFrame(NDFrame):
"Setting max_rows=60, overwrite if different behaviour is required.")
max_rows = 60
# if the size of the index is larger than max_rows, only show 10 rows
if len(self) > max_rows:
max_rows = 10
# Create a slightly bigger dataframe than display
df = self._build_repr_df(max_rows + 1, max_cols)

View File

@ -19,7 +19,7 @@ class TestDataFrameRepr(TestData):
ed_head_101_str = ed_head_101.to_string()
pd_head_101_str = pd_head_101.to_string(max_rows=60)
assert pd_head_101_str == ed_head_101_str
assert pd_head_101_str == ed_head_101_str
def test_head_11_to_string2(self):
ed_flights = self.ed_flights()
@ -33,6 +33,16 @@ 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()
def test_repr(self):
ed_ecommerce = self.ed_ecommerce()
pd_ecommerce = self.pd_ecommerce()