Skip to content

Commit 9219433

Browse files
author
y-p
committed
ENH: special case HTML repr behaviour on ipnb GH3573
PTF
1 parent 26e5e30 commit 9219433

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

pandas/core/frame.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -621,19 +621,26 @@ def _repr_fits_vertical_(self):
621621
max_rows = max_rows or height +1
622622
return len(self) <= min(max_rows, height)
623623

624-
def _repr_fits_horizontal_(self):
624+
def _repr_fits_horizontal_(self,ignore_width=False):
625625
"""
626626
Check if full repr fits in horizontal boundaries imposed by the display
627627
options width and max_columns. In case off non-interactive session, no
628628
boundaries apply.
629+
630+
ignore_width is here so ipnb+HTML output can behave the way
631+
users expect. display.max_columns remains in effect.
632+
GH3541, GH3573
629633
"""
634+
635+
# everytime you add an if-clause here, god slaughters a kitten.
636+
# please. think of the kittens.
630637
width, height = fmt.get_console_size()
631638
max_columns = get_option("display.max_columns")
632639
nb_columns = len(self.columns)
633640

634641
# exceed max columns
635642
if ((max_columns and nb_columns > max_columns) or
636-
(width and nb_columns > (width // 2))):
643+
((not ignore_width) and width and nb_columns > (width // 2))):
637644
return False
638645

639646
if width is None:
@@ -655,7 +662,12 @@ def _repr_fits_horizontal_(self):
655662
d.to_string(buf=buf)
656663
value = buf.getvalue()
657664
repr_width = max([len(l) for l in value.split('\n')])
658-
return repr_width <= width
665+
666+
# special case ipnb+HTML repr
667+
if not ignore_width:
668+
return repr_width <= width
669+
else:
670+
return True
659671

660672
def __str__(self):
661673
"""
@@ -731,12 +743,16 @@ def _repr_html_(self):
731743
Return a html representation for a particular DataFrame.
732744
Mainly for IPython notebook.
733745
"""
746+
# ipnb in html repr mode allows scrolling
747+
# users strongly prefer to h-scroll a wide HTML table in the browser
748+
# then to get a summary view. GH3541, GH3573
749+
ipnbh = com.in_ipnb() and get_option('display.notebook_repr_html')
734750

735751
if get_option("display.notebook_repr_html"):
736752
fits_vertical = self._repr_fits_vertical_()
737753
fits_horizontal = False
738754
if fits_vertical:
739-
fits_horizontal = self._repr_fits_horizontal_()
755+
fits_horizontal = self._repr_fits_horizontal_(ignore_width=ipnbh)
740756

741757
if fits_horizontal and fits_vertical:
742758
return ('<div style="max-height:1000px;'

0 commit comments

Comments
 (0)