@@ -435,9 +435,10 @@ def __nonzero__(self):
435
435
# e.g. "if frame: ..."
436
436
return len (self .columns ) > 0 and len (self .index ) > 0
437
437
438
- def __repr__ (self ):
438
+ def _need_info_repr_ (self ):
439
439
"""
440
- Return a string representation for a particular DataFrame
440
+ Check if it is needed to use info/summary view to represent a
441
+ particular DataFrame.
441
442
"""
442
443
config = fmt .print_config
443
444
@@ -446,35 +447,50 @@ def __repr__(self):
446
447
else config .max_rows )
447
448
max_columns = config .max_columns
448
449
449
- buf = StringIO ()
450
450
if max_columns > 0 :
451
- if len (self .index ) < max_rows and \
451
+ if len (self .index ) <= max_rows and \
452
452
len (self .columns ) <= max_columns :
453
- self . to_string ( buf = buf )
453
+ return False
454
454
else :
455
- self . info ( buf = buf , verbose = self . _verbose_info )
455
+ return True
456
456
else :
457
457
if len (self .index ) > max_rows :
458
- self . info ( buf = buf , verbose = self . _verbose_info )
458
+ return True
459
459
else :
460
+ buf = StringIO ()
460
461
self .to_string (buf = buf )
461
462
value = buf .getvalue ()
462
463
if max ([len (l ) for l in value .split ('\n ' )]) > terminal_width :
463
- buf = StringIO ()
464
- self .info (buf = buf , verbose = self ._verbose_info )
465
- value = buf .getvalue ()
466
- return com .console_encode (value )
467
- return com .console_encode (buf .getvalue ())
464
+ return True
465
+ else :
466
+ return False
467
+
468
+ def __repr__ (self ):
469
+ """
470
+ Return a string representation for a particular DataFrame
471
+ """
472
+ buf = StringIO ()
473
+ if self ._need_info_repr_ ():
474
+ self .info (buf = buf , verbose = self ._verbose_info )
475
+ else :
476
+ self .to_string (buf = buf )
477
+ value = buf .getvalue ()
478
+ return com .console_encode (value )
468
479
469
480
def _repr_html_ (self ):
470
- if len (self .index ) <= 1000 and len (self .columns )<= 20 :
471
- return ('<div style="max-height:1000px;'
472
- 'max-width:1500px;overflow:auto;">' +
473
- self .to_html () + '</div>' )
481
+ """
482
+ Return a html representation for a particular DataFrame.
483
+ Mainly for IPython notebook.
484
+ """
485
+ if fmt .print_config .notebook_repr_html :
486
+ if self ._need_info_repr_ ():
487
+ return None
488
+ else :
489
+ return ('<div style="max-height:1000px;'
490
+ 'max-width:1500px;overflow:auto;">\n ' +
491
+ self .to_html () + '\n </div>' )
474
492
else :
475
- buf = StringIO ()
476
- self .info (buf = buf , verbose = self ._verbose_info )
477
- return '<pre>' + com .console_encode (buf .getvalue ()) + '</pre>'
493
+ return None
478
494
479
495
def __iter__ (self ):
480
496
"""
0 commit comments