Skip to content

Commit 7c59e57

Browse files
author
y-p
committed
ENH: fix df.repr() for scripts (keep GH1611 away), accept None for max_cols/rows
1 parent d477b09 commit 7c59e57

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

pandas/core/config_init.py

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
This sets the maximum number of rows pandas should output when printing
3636
out various output. For example, this value determines whether the repr()
3737
for a dataframe prints out fully or just a summary repr.
38+
'None' value means unlimited.
3839
"""
3940

4041
pc_max_cols_doc = """
@@ -46,6 +47,7 @@
4647
format in case all columns would not fit vertically. The IPython notebook,
4748
IPython qtconsole, or IDLE do not run in a terminal and hence it is not
4849
possible to do correct auto-detection.
50+
'None' value means unlimited.
4951
"""
5052

5153
pc_max_info_cols_doc = """

pandas/core/frame.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,20 @@ def __nonzero__(self):
602602
def _repr_fits_vertical_(self):
603603
"""
604604
Check if full repr fits in vertical boundaries imposed by the display
605-
options height and max_rows. In case off non-interactive session,
605+
options height and max_rows. In case of non-interactive session,
606606
no boundaries apply.
607607
"""
608608
width, height = fmt.get_console_size()
609+
max_rows = get_option("display.max_rows")
609610

610-
# excluding column axis area
611-
max_rows = get_option("display.max_rows") or height
612-
return len(self) <= min(max_rows, height)
611+
if height is None and max_rows is None:
612+
return True
613+
614+
else:
615+
# min of two, where one may be None
616+
height = height or max_rows +1
617+
max_rows = max_rows or height +1
618+
return len(self) <= min(max_rows, height)
613619

614620
def _repr_fits_horizontal_(self):
615621
"""
@@ -618,13 +624,18 @@ def _repr_fits_horizontal_(self):
618624
boundaries apply.
619625
"""
620626
width, height = fmt.get_console_size()
621-
622627
max_columns = get_option("display.max_columns")
623628
nb_columns = len(self.columns)
629+
630+
# exceed max columns
624631
if ((max_columns and nb_columns > max_columns) or
625-
(nb_columns > (width // 2))):
632+
(width and nb_columns > (width // 2))):
626633
return False
627634

635+
if width is None:
636+
# no sense finding width of repr if no width set
637+
return True
638+
628639
buf = StringIO()
629640

630641
# only care about the stuff we'll actually print out
@@ -635,7 +646,7 @@ def _repr_fits_horizontal_(self):
635646
# min of two, where one may be None
636647
height = height or max_rows +1
637648
max_rows = max_rows or height +1
638-
d=d.iloc[:min(max_rows, height)]
649+
d=d.iloc[:min(max_rows, height,len(d))]
639650

640651
d.to_string(buf=buf)
641652
value = buf.getvalue()
@@ -1593,7 +1604,7 @@ def info(self, verbose=True, buf=None, max_cols=None):
15931604

15941605
# hack
15951606
if max_cols is None:
1596-
max_cols = get_option('display.max_info_columns')
1607+
max_cols = get_option('display.max_info_columns',len(self.columns)+1)
15971608

15981609
if verbose and len(self.columns) <= max_cols:
15991610
lines.append('Data columns (total %d columns):' % len(self.columns))

0 commit comments

Comments
 (0)