Skip to content

Commit cf91f46

Browse files
committed
ENH: make expand_frame_repr true by default, change max cols/rows default options per #2436
1 parent cde9690 commit cf91f46

File tree

4 files changed

+23
-37
lines changed

4 files changed

+23
-37
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pandas 0.10.0
4242
- New option configuration system and functions `set_option`, `get_option`,
4343
`describe_option`, and `reset_option`. Deprecate `set_printoptions` and
4444
`reset_printoptions` (#2393)
45+
- Wide DataFrames can be viewed more easily in the console with new
46+
`expand_frame_repr` and `line_width` configuration options. This is on by
47+
default now (#2436)
4548

4649
**Experimental Features**
4750

pandas/core/config_init.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@
119119
cf.register_option('precision', 7, pc_precision_doc, validator=is_int)
120120
cf.register_option('float_format', None, float_format_doc)
121121
cf.register_option('column_space', 12, validator=is_int)
122-
cf.register_option('max_rows', 200, pc_max_rows_doc, validator=is_int)
122+
cf.register_option('max_rows', 100, pc_max_rows_doc, validator=is_int)
123123
cf.register_option('max_colwidth', 50, max_colwidth_doc, validator=is_int)
124-
cf.register_option('max_columns', 0, pc_max_cols_doc, validator=is_int)
124+
cf.register_option('max_columns', 20, pc_max_cols_doc, validator=is_int)
125125
cf.register_option('colheader_justify', 'right', colheader_justify_doc,
126126
validator=is_text)
127127
cf.register_option('notebook_repr_html', True, pc_nb_repr_h_doc,
@@ -136,7 +136,7 @@
136136
validator=is_bool)
137137
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc,
138138
validator=is_text)
139-
cf.register_option('expand_frame_repr', False, pc_expand_repr_doc)
139+
cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
140140
cf.register_option('line_width', 80, pc_line_width_doc)
141141

142142
tc_interactive_doc="""

pandas/core/frame.py

+4-28
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ def _need_info_repr_(self):
595595
expand_repr = get_option("print.expand_frame_repr")
596596

597597
if max_columns > 0:
598-
if len(self.index) <= max_rows and \
599-
(len(self.columns) <= max_columns or expand_repr):
598+
if (len(self.index) <= max_rows and
599+
(len(self.columns) <= max_columns and expand_repr)):
600600
return False
601601
else:
602602
return True
@@ -661,32 +661,8 @@ def __unicode__(self):
661661
return value
662662

663663
def _need_wide_repr(self):
664-
if com.in_qtconsole():
665-
terminal_width, terminal_height = 100, 100
666-
else:
667-
terminal_width, terminal_height = get_terminal_size()
668-
max_columns = get_option("print.max_columns")
669-
expand_repr = get_option("print.expand_frame_repr")
670-
671-
if max_columns > 0:
672-
if len(self.columns) > max_columns and expand_repr:
673-
return True
674-
else:
675-
# save us
676-
if (com.in_interactive_session() and
677-
len(self.columns) > terminal_width // 2 and
678-
expand_repr):
679-
return True
680-
else:
681-
buf = StringIO()
682-
self.to_string(buf=buf)
683-
value = buf.getvalue()
684-
if (max([len(l) for l in value.split('\n')]) > terminal_width
685-
and com.in_interactive_session()
686-
and expand_repr):
687-
return True
688-
689-
return False
664+
return (get_option("print.expand_frame_repr")
665+
and com.in_interactive_session())
690666

691667
def __repr__(self):
692668
"""

pandas/tests/test_format.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import pandas.util.testing as tm
2121
import pandas
2222
import pandas as pd
23-
from pandas.core.config import set_option,get_option
23+
from pandas.core.config import (set_option, get_option,
24+
reset_option)
2425

2526
_frame = DataFrame(tm.getSeriesData())
2627

@@ -404,6 +405,7 @@ def test_wide_repr(self):
404405
set_option('test.interactive', True)
405406
col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
406407
df = DataFrame([col(20, 25) for _ in range(10)])
408+
set_option('print.expand_frame_repr', False)
407409
rep_str = repr(df)
408410
set_option('print.expand_frame_repr', True)
409411
wide_repr = repr(df)
@@ -413,7 +415,7 @@ def test_wide_repr(self):
413415
wider_repr = repr(df)
414416
self.assert_(len(wider_repr) < len(wide_repr))
415417

416-
set_option('print.expand_frame_repr', False)
418+
reset_option('print.expand_frame_repr')
417419
set_option('test.interactive', False)
418420
set_option('print.line_width', 80)
419421

@@ -422,6 +424,8 @@ def test_wide_repr_named(self):
422424
col = lambda l, k: [tm.rands(k) for _ in xrange(l)]
423425
df = DataFrame([col(20, 25) for _ in range(10)])
424426
df.index.name = 'DataFrame Index'
427+
set_option('print.expand_frame_repr', False)
428+
425429
rep_str = repr(df)
426430
set_option('print.expand_frame_repr', True)
427431
wide_repr = repr(df)
@@ -434,7 +438,7 @@ def test_wide_repr_named(self):
434438
for line in wide_repr.splitlines()[1::13]:
435439
self.assert_('DataFrame Index' in line)
436440

437-
set_option('print.expand_frame_repr', False)
441+
reset_option('print.expand_frame_repr')
438442
set_option('test.interactive', False)
439443
set_option('print.line_width', 80)
440444

@@ -446,6 +450,7 @@ def test_wide_repr_multiindex(self):
446450
df = DataFrame([col(20, 25) for _ in range(10)],
447451
index=midx)
448452
df.index.names = ['Level 0', 'Level 1']
453+
set_option('print.expand_frame_repr', False)
449454
rep_str = repr(df)
450455
set_option('print.expand_frame_repr', True)
451456
wide_repr = repr(df)
@@ -458,7 +463,7 @@ def test_wide_repr_multiindex(self):
458463
for line in wide_repr.splitlines()[1::13]:
459464
self.assert_('Level 0 Level 1' in line)
460465

461-
set_option('print.expand_frame_repr', False)
466+
reset_option('print.expand_frame_repr')
462467
set_option('test.interactive', False)
463468
set_option('print.line_width', 80)
464469

@@ -472,6 +477,7 @@ def test_wide_repr_multiindex_cols(self):
472477
df = DataFrame([col(20, 25) for _ in range(10)],
473478
index=midx, columns=mcols)
474479
df.index.names = ['Level 0', 'Level 1']
480+
set_option('print.expand_frame_repr', False)
475481
rep_str = repr(df)
476482
set_option('print.expand_frame_repr', True)
477483
wide_repr = repr(df)
@@ -483,14 +489,15 @@ def test_wide_repr_multiindex_cols(self):
483489

484490
self.assert_(len(wide_repr.splitlines()) == 14 * 10 - 1)
485491

486-
set_option('print.expand_frame_repr', False)
492+
reset_option('print.expand_frame_repr')
487493
set_option('test.interactive', False)
488494
set_option('print.line_width', 80)
489495

490496
def test_wide_repr_unicode(self):
491497
set_option('test.interactive', True)
492498
col = lambda l, k: [tm.randu(k) for _ in xrange(l)]
493499
df = DataFrame([col(20, 25) for _ in range(10)])
500+
set_option('print.expand_frame_repr', False)
494501
rep_str = repr(df)
495502
set_option('print.expand_frame_repr', True)
496503
wide_repr = repr(df)
@@ -500,7 +507,7 @@ def test_wide_repr_unicode(self):
500507
wider_repr = repr(df)
501508
self.assert_(len(wider_repr) < len(wide_repr))
502509

503-
set_option('print.expand_frame_repr', False)
510+
reset_option('print.expand_frame_repr')
504511
set_option('test.interactive', False)
505512
set_option('print.line_width', 80)
506513

0 commit comments

Comments
 (0)