Skip to content

Commit 9ab2385

Browse files
author
y-p
committed
Merge pull request #6041 from hayd/master (reworked)
* hayd-show_dimensions_option: DOC: add show_dimensions to faq ENH: html repr respects show_dimensions ENH: add show_dimensions display config
2 parents 8e3bf5d + a9f34f3 commit 9ab2385

File tree

6 files changed

+37
-3
lines changed

6 files changed

+37
-3
lines changed

doc/source/faq.rst

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ As of 0.13, these are the relevant options, all under the `display` namespace,
4747
truncated table or, with this set to 'info', as a short summary view.
4848
- max_columns (default 20): max dataframe columns to display.
4949
- max_rows (default 60): max dataframe rows display.
50+
- show_dimensions (default True): controls the display of the row/col counts footer.
5051

5152
Two additional options only apply to displaying DataFrames in terminals,
5253
not to the HTML view:

doc/source/v0.13.1.txt

+10
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

+6-1
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

+4-2
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

@@ -485,11 +486,12 @@ def _repr_html_(self):
485486
if get_option("display.notebook_repr_html"):
486487
max_rows = get_option("display.max_rows")
487488
max_cols = get_option("display.max_columns")
489+
show_dimensions = get_option("display.show_dimensions")
488490

489491
return ('<div style="max-height:1000px;'
490492
'max-width:1500px;overflow:auto;">\n' +
491493
self.to_html(max_rows=max_rows, max_cols=max_cols,
492-
show_dimensions=True) + '\n</div>')
494+
show_dimensions=show_dimensions) + '\n</div>')
493495
else:
494496
return None
495497

pandas/tests/test_format.py

+7
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,13 @@ def test_repr_html(self):
14281428

14291429
fmt.reset_option('^display.')
14301430

1431+
df = DataFrame([[1, 2], [3, 4]])
1432+
self.assertTrue('2 rows' in df._repr_html_())
1433+
fmt.set_option('display.show_dimensions', False)
1434+
self.assertFalse('2 rows' in df._repr_html_())
1435+
1436+
fmt.reset_option('^display.')
1437+
14311438
def test_repr_html_wide(self):
14321439
row = lambda l, k: [tm.rands(k) for _ in range(l)]
14331440
max_cols = get_option('display.max_columns')

pandas/tests/test_frame.py

+9
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)