Skip to content

Commit e479948

Browse files
committed
BUG: fix expand_frame_repr
1 parent 0da44db commit e479948

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

pandas/core/frame.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -599,39 +599,47 @@ def empty(self):
599599
def __nonzero__(self):
600600
raise ValueError("Cannot call bool() on DataFrame.")
601601

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+
602608
def _need_info_repr_(self):
603609
"""
604610
Check if it is needed to use info/summary view to represent a
605611
particular DataFrame.
606612
"""
607-
if not get_option("display.expand_frame_repr"):
608-
return True
609-
610613
if com.in_qtconsole():
611614
terminal_width, terminal_height = 100, 100
612615
else:
613616
terminal_width, terminal_height = get_terminal_size()
614617
max_rows = (terminal_height if get_option("display.max_rows") == 0
615618
else get_option("display.max_rows"))
616619
max_columns = get_option("display.max_columns")
620+
expand_repr = get_option("display.expand_frame_repr")
621+
line_width = get_option('display.line_width')
617622

618623
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)):
623626
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
624635
else:
625636
# save us
626637
if (len(self.index) > max_rows or
627638
(com.in_interactive_session() and
628639
len(self.columns) > terminal_width // 2)):
629640
return True
630641
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
635643
and com.in_interactive_session()):
636644
return True
637645
else:

0 commit comments

Comments
 (0)