From f5d73ad7b76c489a535f1a307481fa475f1d4e6d Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Wed, 22 Jan 2014 14:45:16 -0800 Subject: [PATCH 1/3] ENH add show_dimensions display config --- doc/source/v0.13.1.txt | 10 ++++++++++ pandas/core/config_init.py | 7 ++++++- pandas/core/frame.py | 3 ++- pandas/tests/test_frame.py | 9 +++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/source/v0.13.1.txt b/doc/source/v0.13.1.txt index 08c8eb76caaf8..c1aa97e5a8773 100644 --- a/doc/source/v0.13.1.txt +++ b/doc/source/v0.13.1.txt @@ -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`. .. ipython:: python diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index c617c58c527a8..9533c0921e1e3 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -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. @@ -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. @@ -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, diff --git a/pandas/core/frame.py b/pandas/core/frame.py index adb7b2d2b2691..6baf9b0960621 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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() diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index f122a88fe7a25..e45309a19ed9e 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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() From 77165d8b4d3559b862a16091c8a0601fac80c89f Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Wed, 22 Jan 2014 16:54:15 -0800 Subject: [PATCH 2/3] ENH html repr respects show_dimensions --- pandas/core/frame.py | 3 ++- pandas/tests/test_format.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6baf9b0960621..d40c7e49fc0c9 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -485,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 ('
\n' + self.to_html(max_rows=max_rows, max_cols=max_cols, - show_dimensions=True) + '\n
') + show_dimensions=show_dimensions) + '\n') else: return None diff --git a/pandas/tests/test_format.py b/pandas/tests/test_format.py index d0c783725f8bb..ebb2e351c7c1c 100644 --- a/pandas/tests/test_format.py +++ b/pandas/tests/test_format.py @@ -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') From 584760afb594aaa43841e83fc92c03776cf39ad1 Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Sat, 25 Jan 2014 20:19:14 -0800 Subject: [PATCH 3/3] DOC add show_dimensions to faq --- doc/source/faq.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/faq.rst b/doc/source/faq.rst index 68f6e3d53cdca..0fc925dad8b61 100644 --- a/doc/source/faq.rst +++ b/doc/source/faq.rst @@ -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: