@@ -605,57 +605,62 @@ def __nonzero__(self):
605605
606606 def _repr_fits_vertical_ (self ):
607607 """
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.
611609 """
612- width , height = fmt .get_console_size ()
613610 max_rows = get_option ("display.max_rows" )
611+ return len (self ) <= max_rows
614612
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 ):
625614 """
626615 Check if full repr fits in horizontal boundaries imposed by the display
627616 options width and max_columns. In case off non-interactive session, no
628617 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
629622 """
623+
630624 width , height = fmt .get_console_size ()
631625 max_columns = get_option ("display.max_columns" )
632626 nb_columns = len (self .columns )
633627
634628 # exceed max columns
635629 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 ))):
637631 return False
638632
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
641635 return True
642636
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
643647 buf = StringIO ()
644648
645649 # only care about the stuff we'll actually print out
646650 # and to_string on entire frame may be expensive
647651 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
650654 # 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
654658
655659 d .to_string (buf = buf )
656660 value = buf .getvalue ()
657661 repr_width = max ([len (l ) for l in value .split ('\n ' )])
658- return repr_width <= width
662+
663+ return repr_width < width
659664
660665 def __str__ (self ):
661666 """
@@ -697,14 +702,11 @@ def __unicode__(self):
697702 if fits_vertical and fits_horizontal :
698703 self .to_string (buf = buf )
699704 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)
708710 self .to_string (buf = buf , line_width = width )
709711 else :
710712 max_info_rows = get_option ('display.max_info_rows' )
@@ -731,12 +733,22 @@ def _repr_html_(self):
731733 Return a html representation for a particular DataFrame.
732734 Mainly for IPython notebook.
733735 """
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' )
734746
735747 if get_option ("display.notebook_repr_html" ):
736748 fits_vertical = self ._repr_fits_vertical_ ()
737749 fits_horizontal = False
738750 if fits_vertical :
739- fits_horizontal = self ._repr_fits_horizontal_ ()
751+ fits_horizontal = self ._repr_fits_horizontal_ (ignore_width = ipnbh )
740752
741753 if fits_horizontal and fits_vertical :
742754 return ('<div style="max-height:1000px;'
@@ -870,7 +882,7 @@ def __contains__(self, key):
870882
871883 # Python 2 division methods
872884 if not py3compat .PY3 :
873- __div__ = _arith_method (operator .div , '__div__' , '/' ,
885+ __div__ = _arith_method (operator .div , '__div__' , '/' ,
874886 default_axis = None , fill_zeros = np .inf )
875887 __rdiv__ = _arith_method (lambda x , y : y / x , '__rdiv__' ,
876888 default_axis = None , fill_zeros = np .inf )
0 commit comments