@@ -605,57 +605,62 @@ def __nonzero__(self):
605
605
606
606
def _repr_fits_vertical_ (self ):
607
607
"""
608
- Check if full repr fits in vertical boundaries imposed by the display
609
- options height and max_rows. In case of non-interactive session,
610
- no boundaries apply.
608
+ Check length against max_rows.
611
609
"""
612
- width , height = fmt .get_console_size ()
613
610
max_rows = get_option ("display.max_rows" )
611
+ return len (self ) <= max_rows
614
612
615
- if height is None and max_rows is None :
616
- return True
617
-
618
- else :
619
- # min of two, where one may be None
620
- height = height or max_rows + 1
621
- max_rows = max_rows or height + 1
622
- return len (self ) <= min (max_rows , height )
623
-
624
- def _repr_fits_horizontal_ (self ):
613
+ def _repr_fits_horizontal_ (self ,ignore_width = False ):
625
614
"""
626
615
Check if full repr fits in horizontal boundaries imposed by the display
627
616
options width and max_columns. In case off non-interactive session, no
628
617
boundaries apply.
618
+
619
+ ignore_width is here so ipnb+HTML output can behave the way
620
+ users expect. display.max_columns remains in effect.
621
+ GH3541, GH3573
629
622
"""
623
+
630
624
width , height = fmt .get_console_size ()
631
625
max_columns = get_option ("display.max_columns" )
632
626
nb_columns = len (self .columns )
633
627
634
628
# exceed max columns
635
629
if ((max_columns and nb_columns > max_columns ) or
636
- (width and nb_columns > (width // 2 ))):
630
+ (( not ignore_width ) and width and nb_columns > (width // 2 ))):
637
631
return False
638
632
639
- if width is None :
640
- # no sense finding width of repr if no width set
633
+ if ( ignore_width # used by repr_html under IPython notebook
634
+ or not com . in_interactive_session ()): # scripts ignore terminal dims
641
635
return True
642
636
637
+ if (get_option ('display.width' ) is not None or
638
+ com .in_ipython_frontend ()):
639
+ # check at least the column row for excessive width
640
+ max_rows = 1
641
+ else :
642
+ max_rows = get_option ("display.max_rows" )
643
+
644
+ # when auto-detecting, so width=None and not in ipython front end
645
+ # check whether repr fits horizontal by actualy checking
646
+ # the width of the rendered repr
643
647
buf = StringIO ()
644
648
645
649
# only care about the stuff we'll actually print out
646
650
# and to_string on entire frame may be expensive
647
651
d = self
648
- max_rows = get_option ( "display.max_rows" )
649
- if not (height is None and max_rows is None ):
652
+
653
+ if not (max_rows is None ): # unlimited rows
650
654
# min of two, where one may be None
651
- height = height or max_rows + 1
652
- max_rows = max_rows or height + 1
653
- d = d . iloc [: min ( max_rows , height , len ( d ))]
655
+ d = d . iloc [: min ( max_rows , len ( d ))]
656
+ else :
657
+ return True
654
658
655
659
d .to_string (buf = buf )
656
660
value = buf .getvalue ()
657
661
repr_width = max ([len (l ) for l in value .split ('\n ' )])
658
- return repr_width <= width
662
+
663
+ return repr_width < width
659
664
660
665
def __str__ (self ):
661
666
"""
@@ -697,14 +702,11 @@ def __unicode__(self):
697
702
if fits_vertical and fits_horizontal :
698
703
self .to_string (buf = buf )
699
704
else :
700
- width , height = fmt .get_console_size ()
701
- max_rows = get_option ("display.max_rows" ) or height
702
- # expand_repr basically takes the extrac columns that don't
703
- # fit the width, and creates a new page, which increases
704
- # the effective row count. check number of cols agaibst
705
- # max rows to catch wrapping. that would exceed max_rows.
706
- if (get_option ("display.expand_frame_repr" ) and fits_vertical and
707
- len (self .columns ) < max_rows ):
705
+ width , _ = fmt .get_console_size ()
706
+ max_rows = get_option ("display.max_rows" )
707
+ if (get_option ("display.expand_frame_repr" )
708
+ and fits_vertical ):
709
+ # and len(self.columns) < max_rows)
708
710
self .to_string (buf = buf , line_width = width )
709
711
else :
710
712
max_info_rows = get_option ('display.max_info_rows' )
@@ -731,12 +733,22 @@ def _repr_html_(self):
731
733
Return a html representation for a particular DataFrame.
732
734
Mainly for IPython notebook.
733
735
"""
736
+ # ipnb in html repr mode allows scrolling
737
+ # users strongly prefer to h-scroll a wide HTML table in the browser
738
+ # then to get a summary view. GH3541, GH3573
739
+ ipnbh = com .in_ipnb () and get_option ('display.notebook_repr_html' )
740
+
741
+ # qtconsole doesn't report it's line width, and also
742
+ # behaves badly when outputting an HTML table
743
+ # that doesn't fit the window, so disable it.
744
+ if com .in_qtconsole ():
745
+ raise ValueError ('Disable HTML output in QtConsole' )
734
746
735
747
if get_option ("display.notebook_repr_html" ):
736
748
fits_vertical = self ._repr_fits_vertical_ ()
737
749
fits_horizontal = False
738
750
if fits_vertical :
739
- fits_horizontal = self ._repr_fits_horizontal_ ()
751
+ fits_horizontal = self ._repr_fits_horizontal_ (ignore_width = ipnbh )
740
752
741
753
if fits_horizontal and fits_vertical :
742
754
return ('<div style="max-height:1000px;'
@@ -870,7 +882,7 @@ def __contains__(self, key):
870
882
871
883
# Python 2 division methods
872
884
if not py3compat .PY3 :
873
- __div__ = _arith_method (operator .div , '__div__' , '/' ,
885
+ __div__ = _arith_method (operator .div , '__div__' , '/' ,
874
886
default_axis = None , fill_zeros = np .inf )
875
887
__rdiv__ = _arith_method (lambda x , y : y / x , '__rdiv__' ,
876
888
default_axis = None , fill_zeros = np .inf )
0 commit comments