@@ -25,8 +25,8 @@ class HTMLFormatter(TableFormatter):
25
25
26
26
indent_delta = 2
27
27
28
- def __init__ (self , formatter , classes = None , max_rows = None , max_cols = None ,
29
- notebook = False , border = None , table_id = None ):
28
+ def __init__ (self , formatter , classes = None , notebook = False , border = None ,
29
+ table_id = None ):
30
30
self .fmt = formatter
31
31
self .classes = classes
32
32
@@ -35,18 +35,21 @@ def __init__(self, formatter, classes=None, max_rows=None, max_cols=None,
35
35
self .elements = []
36
36
self .bold_rows = self .fmt .kwds .get ('bold_rows' , False )
37
37
self .escape = self .fmt .kwds .get ('escape' , True )
38
-
39
- self .max_rows = max_rows or len (self .fmt .frame )
40
- self .max_cols = max_cols or len (self .fmt .columns )
41
38
self .show_dimensions = self .fmt .show_dimensions
42
- self .is_truncated = (self .max_rows < len (self .fmt .frame ) or
43
- self .max_cols < len (self .fmt .columns ))
44
39
self .notebook = notebook
45
40
if border is None :
46
41
border = get_option ('display.html.border' )
47
42
self .border = border
48
43
self .table_id = table_id
49
44
45
+ @property
46
+ def is_truncated (self ):
47
+ return self .fmt .is_truncated
48
+
49
+ @property
50
+ def ncols (self ):
51
+ return len (self .fmt .tr_frame .columns )
52
+
50
53
def write (self , s , indent = 0 ):
51
54
rs = pprint_thing (s )
52
55
self .elements .append (' ' * indent + rs )
@@ -301,12 +304,8 @@ def _write_header(self, indent):
301
304
if all ((self .fmt .has_index_names ,
302
305
self .fmt .index ,
303
306
self .fmt .show_index_names )):
304
- row = ([x if x is not None else ''
305
- for x in self .frame .index .names ] +
306
- ['' ] * min (len (self .columns ), self .max_cols ))
307
- if truncate_h :
308
- ins_col = row_levels + self .fmt .tr_col_num
309
- row .insert (ins_col , '' )
307
+ row = ([x if x is not None else '' for x in self .frame .index .names ]
308
+ + ['' ] * (self .ncols + (1 if truncate_h else 0 )))
310
309
self .write_tr (row , indent , self .indent_delta , header = True )
311
310
312
311
indent -= self .indent_delta
@@ -318,9 +317,7 @@ def _write_body(self, indent):
318
317
self .write ('<tbody>' , indent )
319
318
indent += self .indent_delta
320
319
321
- fmt_values = {}
322
- for i in range (min (len (self .columns ), self .max_cols )):
323
- fmt_values [i ] = self .fmt ._format_col (i )
320
+ fmt_values = {i : self .fmt ._format_col (i ) for i in range (self .ncols )}
324
321
325
322
# write values
326
323
if self .fmt .index and isinstance (self .frame .index , ABCMultiIndex ):
@@ -338,7 +335,6 @@ def _write_regular_rows(self, fmt_values, indent):
338
335
truncate_h = self .fmt .truncate_h
339
336
truncate_v = self .fmt .truncate_v
340
337
341
- ncols = len (self .fmt .tr_frame .columns )
342
338
nrows = len (self .fmt .tr_frame )
343
339
344
340
if self .fmt .index :
@@ -362,7 +358,7 @@ def _write_regular_rows(self, fmt_values, indent):
362
358
row = []
363
359
if self .fmt .index :
364
360
row .append (index_values [i ])
365
- row .extend (fmt_values [j ][i ] for j in range (ncols ))
361
+ row .extend (fmt_values [j ][i ] for j in range (self . ncols ))
366
362
367
363
if truncate_h :
368
364
dot_col_ix = self .fmt .tr_col_num + row_levels
@@ -376,7 +372,6 @@ def _write_hierarchical_rows(self, fmt_values, indent):
376
372
truncate_h = self .fmt .truncate_h
377
373
truncate_v = self .fmt .truncate_v
378
374
frame = self .fmt .tr_frame
379
- ncols = len (frame .columns )
380
375
nrows = len (frame )
381
376
row_levels = self .frame .index .nlevels
382
377
@@ -454,7 +449,7 @@ def _write_hierarchical_rows(self, fmt_values, indent):
454
449
j += 1
455
450
row .append (v )
456
451
457
- row .extend (fmt_values [j ][i ] for j in range (ncols ))
452
+ row .extend (fmt_values [j ][i ] for j in range (self . ncols ))
458
453
if truncate_h :
459
454
row .insert (row_levels - sparse_offset +
460
455
self .fmt .tr_col_num , '...' )
@@ -466,7 +461,7 @@ def _write_hierarchical_rows(self, fmt_values, indent):
466
461
sparsify = False , adjoin = False , names = False )))
467
462
row = []
468
463
row .extend (idx_values [i ])
469
- row .extend (fmt_values [j ][i ] for j in range (ncols ))
464
+ row .extend (fmt_values [j ][i ] for j in range (self . ncols ))
470
465
if truncate_h :
471
466
row .insert (row_levels + self .fmt .tr_col_num , '...' )
472
467
self .write_tr (row , indent , self .indent_delta , tags = None ,
0 commit comments