@@ -599,39 +599,47 @@ def empty(self):
599
599
def __nonzero__ (self ):
600
600
raise ValueError ("Cannot call bool() on DataFrame." )
601
601
602
+ def _to_string_max_line_width (self ):
603
+ buf = StringIO ()
604
+ self .to_string (buf = buf )
605
+ value = buf .getvalue ()
606
+ return max ([len (l ) for l in value .split ('\n ' )])
607
+
602
608
def _need_info_repr_ (self ):
603
609
"""
604
610
Check if it is needed to use info/summary view to represent a
605
611
particular DataFrame.
606
612
"""
607
- if not get_option ("display.expand_frame_repr" ):
608
- return True
609
-
610
613
if com .in_qtconsole ():
611
614
terminal_width , terminal_height = 100 , 100
612
615
else :
613
616
terminal_width , terminal_height = get_terminal_size ()
614
617
max_rows = (terminal_height if get_option ("display.max_rows" ) == 0
615
618
else get_option ("display.max_rows" ))
616
619
max_columns = get_option ("display.max_columns" )
620
+ expand_repr = get_option ("display.expand_frame_repr" )
621
+ line_width = get_option ('display.line_width' )
617
622
618
623
if max_columns > 0 :
619
- if (len (self .index ) <= max_rows and
620
- (len (self .columns ) <= max_columns )):
621
- return False
622
- else :
624
+ if ((len (self .index ) > max_rows ) or
625
+ (len (self .columns ) > max_columns )):
623
626
return True
627
+ else :
628
+ if expand_repr or (line_width is None ):
629
+ return False
630
+ else :
631
+ if len (self .columns ) > (line_width // 2 ):
632
+ return True
633
+ else :
634
+ return self ._to_string_max_line_width () > line_width
624
635
else :
625
636
# save us
626
637
if (len (self .index ) > max_rows or
627
638
(com .in_interactive_session () and
628
639
len (self .columns ) > terminal_width // 2 )):
629
640
return True
630
641
else :
631
- buf = StringIO ()
632
- self .to_string (buf = buf )
633
- value = buf .getvalue ()
634
- if (max ([len (l ) for l in value .split ('\n ' )]) > terminal_width
642
+ if (self ._to_string_max_line_width () > terminal_width
635
643
and com .in_interactive_session ()):
636
644
return True
637
645
else :
0 commit comments