@@ -131,9 +131,16 @@ def repack_row(chunk):
131
131
return None
132
132
return chunk .to_html (max_rows = 1 , max_cols = 5 , show_dimensions = True , index = False , header = False )
133
133
134
+ # Handle sizing, trim html dataframe if output will be truncated
135
+ df_shape = self .shape # grab original shape information for later
136
+ if pd .get_option ("display.max_rows" ) is None or df_shape [0 ] > pd .get_option ("display.max_rows" ):
137
+ html_df = self .head (pd .get_option ("display.min_rows" ) + 1 )
138
+ else :
139
+ html_df = self .copy ()
140
+
134
141
# replace index to ensure proper behavior for duplicate index values
135
- index_values = self .index
136
- html_df = self .reset_index (drop = True )
142
+ index_values = html_df .index
143
+ html_df = html_df .reset_index (drop = True )
137
144
138
145
# Apply repacking to all nested columns
139
146
repr = html_df .style .format (
@@ -152,15 +159,17 @@ def map_true_index(index):
152
159
153
160
# Recover some truncation formatting, limited to head truncation
154
161
if pd .get_option ("display.max_rows" ) is None :
162
+ # Just display header
155
163
return repr .to_html (max_rows = 0 )
156
- elif repr .data .shape [0 ] > pd .get_option ("display.max_rows" ):
164
+ elif df_shape [0 ] > pd .get_option ("display.max_rows" ):
165
+ # when over the max_rows threshold, display with truncation ("..." row at the end)
157
166
html_repr = repr .to_html (max_rows = pd .get_option ("display.min_rows" ))
158
167
else :
159
168
# when under the max_rows threshold, display all rows (behavior of 0 here)
160
169
html_repr = repr .to_html (max_rows = 0 )
161
170
162
171
# Manually append dimensionality to a styler output
163
- html_repr += f"{ repr . data . shape [0 ]} rows x { repr . data . shape [1 ]} columns"
172
+ html_repr += f"{ df_shape [0 ]} rows x { df_shape [1 ]} columns"
164
173
165
174
return html_repr
166
175
0 commit comments