Skip to content

ENH add show_dimensions display config #6041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ As of 0.13, these are the relevant options, all under the `display` namespace,
truncated table or, with this set to 'info', as a short summary view.
- max_columns (default 20): max dataframe columns to display.
- max_rows (default 60): max dataframe rows display.
- show_dimenstions (default True): whether to show number of rows and columns.

Two additional options only apply to displaying DataFrames in terminals,
not to the HTML view:
Expand Down
10 changes: 10 additions & 0 deletions doc/source/v0.13.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ Enhancements
df['diff'] = df['today']-df['age']
df

- Add ``show_dimensions`` display option for the new DataFrame repr:

.. ipython:: python

df = DataFrame([[1, 2], [3, 4]])
pd.set_option('show_dimensions', False)
df

pd.set_option('show_dimensions', True)

- ``Panel.apply`` will work on non-ufuncs. See :ref:`the docs<basics.apply_panel>`.

.. ipython:: python
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
wrap-around across multiple "pages" if it's width exceeds `display.width`.
"""

pc_show_dimensions_doc = """
: boolean
Whether to print out dimensions at the end of DataFrame repr.
"""

pc_line_width_doc = """
: int
Deprecated.
Expand Down Expand Up @@ -163,7 +168,6 @@
If set to None, the number of items to be printed is unlimited.
"""


pc_max_info_rows_doc = """
: int or None
df.info() will usually show null-counts for each column.
Expand Down Expand Up @@ -243,6 +247,7 @@ def mpl_style_cb(key):
cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc,
validator=is_text)
cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
cf.register_option('show_dimensions', True, pc_show_dimensions_doc)
cf.register_option('chop_threshold', None, pc_chop_threshold_doc)
cf.register_option('max_seq_items', 100, pc_max_seq_items)
cf.register_option('mpl_style', None, pc_mpl_style_doc,
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,13 @@ def __unicode__(self):

max_rows = get_option("display.max_rows")
max_cols = get_option("display.max_columns")
show_dimensions = get_option("display.show_dimensions")
if get_option("display.expand_frame_repr"):
width, _ = fmt.get_console_size()
else:
width = None
self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols,
line_width=width, show_dimensions=True)
line_width=width, show_dimensions=show_dimensions)

return buf.getvalue()

Expand Down Expand Up @@ -484,11 +485,12 @@ def _repr_html_(self):
if get_option("display.notebook_repr_html"):
max_rows = get_option("display.max_rows")
max_cols = get_option("display.max_columns")
show_dimensions = get_option("display.show_dimensions")

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

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,13 @@ def test_repr_html(self):

fmt.reset_option('^display.')

df = DataFrame([[1, 2], [3, 4]])
self.assertTrue('2 rows' in df._repr_html_())
fmt.set_option('display.show_dimensions', False)
self.assertFalse('2 rows' in df._repr_html_())

fmt.reset_option('^display.')

def test_repr_html_wide(self):
row = lambda l, k: [tm.rands(k) for _ in range(l)]
max_cols = get_option('display.max_columns')
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,15 @@ def test_repr(self):
self.assertFalse("\r" in repr(df))
self.assertFalse("a\n" in repr(df))

def test_repr_dimensions(self):
df = DataFrame([[1, 2,], [3, 4]])
self.assertTrue("2 rows x 2 columns" in repr(df))

fmt.set_option('display.show_dimensions', False)
self.assertFalse("2 rows x 2 columns" in repr(df))

fmt.reset_option('^display\.')

@slow
def test_repr_big(self):
buf = StringIO()
Expand Down