@@ -621,19 +621,26 @@ def _repr_fits_vertical_(self):
621
621
max_rows = max_rows or height + 1
622
622
return len (self ) <= min (max_rows , height )
623
623
624
- def _repr_fits_horizontal_ (self ):
624
+ def _repr_fits_horizontal_ (self , ignore_width = False ):
625
625
"""
626
626
Check if full repr fits in horizontal boundaries imposed by the display
627
627
options width and max_columns. In case off non-interactive session, no
628
628
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
629
633
"""
634
+
635
+ # everytime you add an if-clause here, god slaughters a kitten.
636
+ # please. think of the kittens.
630
637
width , height = fmt .get_console_size ()
631
638
max_columns = get_option ("display.max_columns" )
632
639
nb_columns = len (self .columns )
633
640
634
641
# exceed max columns
635
642
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 ))):
637
644
return False
638
645
639
646
if width is None :
@@ -655,7 +662,12 @@ def _repr_fits_horizontal_(self):
655
662
d .to_string (buf = buf )
656
663
value = buf .getvalue ()
657
664
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
659
671
660
672
def __str__ (self ):
661
673
"""
@@ -731,12 +743,16 @@ def _repr_html_(self):
731
743
Return a html representation for a particular DataFrame.
732
744
Mainly for IPython notebook.
733
745
"""
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' )
734
750
735
751
if get_option ("display.notebook_repr_html" ):
736
752
fits_vertical = self ._repr_fits_vertical_ ()
737
753
fits_horizontal = False
738
754
if fits_vertical :
739
- fits_horizontal = self ._repr_fits_horizontal_ ()
755
+ fits_horizontal = self ._repr_fits_horizontal_ (ignore_width = ipnbh )
740
756
741
757
if fits_horizontal and fits_vertical :
742
758
return ('<div style="max-height:1000px;'
0 commit comments