79
79
* unset.
80
80
max_rows : int, optional
81
81
Maximum number of rows to display in the console.
82
+ min_rows : int, optional
83
+ The number of rows to display in the console in a truncated repr
84
+ (when number of rows is above `max_rows`).
82
85
max_cols : int, optional
83
86
Maximum number of columns to display in the console.
84
87
show_dimensions : bool, default False
@@ -159,7 +162,7 @@ class SeriesFormatter:
159
162
160
163
def __init__ (self , series , buf = None , length = True , header = True , index = True ,
161
164
na_rep = 'NaN' , name = False , float_format = None , dtype = True ,
162
- max_rows = None ):
165
+ max_rows = None , min_rows = None ):
163
166
self .series = series
164
167
self .buf = buf if buf is not None else StringIO ()
165
168
self .name = name
@@ -168,6 +171,7 @@ def __init__(self, series, buf=None, length=True, header=True, index=True,
168
171
self .length = length
169
172
self .index = index
170
173
self .max_rows = max_rows
174
+ self .min_rows = min_rows
171
175
172
176
if float_format is None :
173
177
float_format = get_option ("display.float_format" )
@@ -179,10 +183,17 @@ def __init__(self, series, buf=None, length=True, header=True, index=True,
179
183
180
184
def _chk_truncate (self ):
181
185
from pandas .core .reshape .concat import concat
186
+ min_rows = self .min_rows
182
187
max_rows = self .max_rows
188
+ # truncation determined by max_rows, actual truncated number of rows
189
+ # used below by min_rows
183
190
truncate_v = max_rows and (len (self .series ) > max_rows )
184
191
series = self .series
185
192
if truncate_v :
193
+ if min_rows :
194
+ # if min_rows is set (not None or 0), set max_rows to minimum
195
+ # of both
196
+ max_rows = min (min_rows , max_rows )
186
197
if max_rows == 1 :
187
198
row_num = max_rows
188
199
series = series .iloc [:max_rows ]
@@ -391,8 +402,8 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
391
402
header = True , index = True , na_rep = 'NaN' , formatters = None ,
392
403
justify = None , float_format = None , sparsify = None ,
393
404
index_names = True , line_width = None , max_rows = None ,
394
- max_cols = None , show_dimensions = False , decimal = '.' ,
395
- table_id = None , render_links = False , ** kwds ):
405
+ min_rows = None , max_cols = None , show_dimensions = False ,
406
+ decimal = '.' , table_id = None , render_links = False , ** kwds ):
396
407
self .frame = frame
397
408
if buf is not None :
398
409
self .buf = _expand_user (_stringify_path (buf ))
@@ -414,6 +425,7 @@ def __init__(self, frame, buf=None, columns=None, col_space=None,
414
425
self .index = index
415
426
self .line_width = line_width
416
427
self .max_rows = max_rows
428
+ self .min_rows = min_rows
417
429
self .max_cols = max_cols
418
430
self .max_rows_displayed = min (max_rows or len (self .frame ),
419
431
len (self .frame ))
@@ -471,6 +483,10 @@ def _chk_truncate(self):
471
483
max_rows = h
472
484
473
485
if not hasattr (self , 'max_rows_adj' ):
486
+ if max_rows :
487
+ if (len (self .frame ) > max_rows ) and self .min_rows :
488
+ # if truncated, set max_rows showed to min_rows
489
+ max_rows = min (self .min_rows , max_rows )
474
490
self .max_rows_adj = max_rows
475
491
if not hasattr (self , 'max_cols_adj' ):
476
492
self .max_cols_adj = max_cols
0 commit comments