@@ -599,32 +599,38 @@ def empty(self):
599
599
def __nonzero__ (self ):
600
600
raise ValueError ("Cannot call bool() on DataFrame." )
601
601
602
- def _repr_fits_boundaries_ (self ):
602
+ def _repr_fits_vertical_ (self ):
603
603
"""
604
- Check if repr fits in boundaries imposed by the following sets of
605
- display options:
606
- * width, height
607
- * max_rows, max_columns
608
- In case off non-interactive session, no boundaries apply.
604
+ Check if full repr fits in vertical boundaries imposed by the display
605
+ options height and max_columns. In case off non-interactive session,
606
+ no boundaries apply.
609
607
"""
610
608
if not com .in_interactive_session ():
611
609
return True
612
610
613
611
terminal_width , terminal_height = get_terminal_size ()
614
612
615
- # check vertical boundaries ( excluding column axis area)
613
+ # excluding column axis area
616
614
max_rows = get_option ("display.max_rows" ) or terminal_height
617
615
display_height = get_option ("display.height" ) or terminal_height
618
- if len (self .index ) > min (max_rows , display_height ):
619
- return False
616
+ return len (self .index ) <= min (max_rows , display_height )
617
+
618
+ def _repr_fits_horizontal_ (self ):
619
+ """
620
+ Check if full repr fits in horizontal boundaries imposed by the display
621
+ options width and max_columns. In case off non-interactive session, no
622
+ boundaries apply.
623
+ """
624
+ if not com .in_interactive_session ():
625
+ return True
626
+
627
+ terminal_width , terminal_height = get_terminal_size ()
620
628
621
- # check horizontal boundaries (including index axis area)
622
629
max_columns = get_option ("display.max_columns" )
623
630
display_width = get_option ("display.width" ) or terminal_width
624
631
nb_columns = len (self .columns )
625
- if max_columns and nb_columns > max_columns :
626
- return False
627
- if nb_columns > (display_width // 2 ):
632
+ if ((max_columns and nb_columns > max_columns ) or
633
+ (nb_columns > (display_width // 2 ))):
628
634
return False
629
635
630
636
buf = StringIO ()
@@ -663,15 +669,17 @@ def __unicode__(self):
663
669
py2/py3.
664
670
"""
665
671
buf = StringIO (u"" )
666
- if self ._repr_fits_boundaries_ ():
672
+ fits_vertical = self ._repr_fits_vertical_ ()
673
+ fits_horizontal = self ._repr_fits_horizontal_ ()
674
+ if fits_vertical and fits_horizontal :
667
675
self .to_string (buf = buf )
668
676
else :
669
677
terminal_width , terminal_height = get_terminal_size ()
670
678
max_rows = get_option ("display.max_rows" ) or terminal_height
671
679
# Expand or info? Decide based on option display.expand_frame_repr
672
680
# and keep it sane for the number of display rows used by the
673
681
# expanded repr.
674
- if (get_option ("display.expand_frame_repr" ) and
682
+ if (get_option ("display.expand_frame_repr" ) and fits_vertical and
675
683
len (self .columns ) < max_rows ):
676
684
line_width = get_option ("display.width" ) or terminal_width
677
685
self .to_string (buf = buf , line_width = line_width )
@@ -703,7 +711,7 @@ def _repr_html_(self):
703
711
raise ValueError ('Disable HTML output in QtConsole' )
704
712
705
713
if get_option ("display.notebook_repr_html" ):
706
- if self ._repr_fits_boundaries_ ():
714
+ if self ._repr_fits_horizontal_ () and self . _repr_fits_vertical_ ():
707
715
return ('<div style="max-height:1000px;'
708
716
'max-width:1500px;overflow:auto;">\n ' +
709
717
self .to_html () + '\n </div>' )
@@ -713,7 +721,10 @@ def _repr_html_(self):
713
721
verbose = (max_info_rows is None or
714
722
self .shape [0 ] <= max_info_rows )
715
723
self .info (buf = buf , verbose = verbose )
716
- info = buf .getvalue ().replace ('<' , '<' ).replace ('>' , '>' )
724
+ info = buf .getvalue ()
725
+ info = info .replace ('&' , r'&' )
726
+ info = info .replace ('<' , r'<' )
727
+ info = info .replace ('>' , r'>' )
717
728
return ('<pre>\n ' + info + '\n </pre>' )
718
729
else :
719
730
return None
0 commit comments