Skip to content

Commit e517159

Browse files
haydy-p
authored andcommitted
ENH: add show_dimensions display config
1 parent 8e3bf5d commit e517159

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

doc/source/v0.13.1.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ Enhancements
104104
df['diff'] = df['today']-df['age']
105105
df
106106

107+
- Add ``show_dimensions`` display option for the new DataFrame repr:
108+
109+
.. ipython:: python
110+
111+
df = DataFrame([[1, 2], [3, 4]])
112+
pd.set_option('show_dimensions', False)
113+
df
114+
115+
pd.set_option('show_dimensions', True)
116+
107117
- ``Panel.apply`` will work on non-ufuncs. See :ref:`the docs<basics.apply_panel>`.
108118

109119
.. ipython:: python

pandas/core/config_init.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
wrap-around across multiple "pages" if it's width exceeds `display.width`.
120120
"""
121121

122+
pc_show_dimensions_doc = """
123+
: boolean
124+
Whether to print out dimensions at the end of DataFrame repr.
125+
"""
126+
122127
pc_line_width_doc = """
123128
: int
124129
Deprecated.
@@ -163,7 +168,6 @@
163168
If set to None, the number of items to be printed is unlimited.
164169
"""
165170

166-
167171
pc_max_info_rows_doc = """
168172
: int or None
169173
df.info() will usually show null-counts for each column.
@@ -243,6 +247,7 @@ def mpl_style_cb(key):
243247
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc,
244248
validator=is_text)
245249
cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
250+
cf.register_option('show_dimensions', True, pc_show_dimensions_doc)
246251
cf.register_option('chop_threshold', None, pc_chop_threshold_doc)
247252
cf.register_option('max_seq_items', 100, pc_max_seq_items)
248253
cf.register_option('mpl_style', None, pc_mpl_style_doc,

pandas/core/frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,13 @@ def __unicode__(self):
451451

452452
max_rows = get_option("display.max_rows")
453453
max_cols = get_option("display.max_columns")
454+
show_dimensions = get_option("display.show_dimensions")
454455
if get_option("display.expand_frame_repr"):
455456
width, _ = fmt.get_console_size()
456457
else:
457458
width = None
458459
self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols,
459-
line_width=width, show_dimensions=True)
460+
line_width=width, show_dimensions=show_dimensions)
460461

461462
return buf.getvalue()
462463

pandas/tests/test_frame.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4175,6 +4175,15 @@ def test_repr(self):
41754175
self.assertFalse("\r" in repr(df))
41764176
self.assertFalse("a\n" in repr(df))
41774177

4178+
def test_repr_dimensions(self):
4179+
df = DataFrame([[1, 2,], [3, 4]])
4180+
self.assertTrue("2 rows x 2 columns" in repr(df))
4181+
4182+
fmt.set_option('display.show_dimensions', False)
4183+
self.assertFalse("2 rows x 2 columns" in repr(df))
4184+
4185+
fmt.reset_option('^display\.')
4186+
41784187
@slow
41794188
def test_repr_big(self):
41804189
buf = StringIO()

0 commit comments

Comments
 (0)