From f78b7321ad489e33b6907bb2bba78b3dd6aebf11 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 18 Aug 2019 11:06:42 +0200 Subject: [PATCH 1/2] DataFrame html repr: also follow min_rows setting --- pandas/core/frame.py | 7 +++++-- pandas/tests/io/formats/test_format.py | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 603a615c1f8cb..b377e571a5abc 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -669,15 +669,18 @@ def _repr_html_(self): if get_option("display.notebook_repr_html"): max_rows = get_option("display.max_rows") + min_rows = get_option("display.min_rows") max_cols = get_option("display.max_columns") show_dimensions = get_option("display.show_dimensions") - return self.to_html( + formatter = fmt.DataFrameFormatter( + self, max_rows=max_rows, + min_rows=min_rows, max_cols=max_cols, show_dimensions=show_dimensions, - notebook=True, ) + return formatter.to_html(notebook=True) else: return None diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index a048e3bb867bd..c0451a0672c89 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -471,28 +471,35 @@ def test_repr_min_rows(self): # default setting no truncation even if above min_rows assert ".." not in repr(df) + assert ".." not in df._repr_html_() df = pd.DataFrame({"a": range(61)}) # default of max_rows 60 triggers truncation if above assert ".." in repr(df) + assert ".." in df._repr_html_() with option_context("display.max_rows", 10, "display.min_rows", 4): # truncated after first two rows assert ".." in repr(df) assert "2 " not in repr(df) + assert "..." in df._repr_html_() + assert "2" not in df._repr_html_() with option_context("display.max_rows", 12, "display.min_rows", None): # when set to None, follow value of max_rows assert "5 5" in repr(df) + assert "5" in df._repr_html_() with option_context("display.max_rows", 10, "display.min_rows", 12): # when set value higher as max_rows, use the minimum assert "5 5" not in repr(df) + assert "5" not in df._repr_html_() with option_context("display.max_rows", None, "display.min_rows", 12): # max_rows of None -> never truncate assert ".." not in repr(df) + assert ".." not in df._repr_html_() def test_str_max_colwidth(self): # GH 7856 From d7c4f0d15a28a89117a516060a92ace6a6b89f7c Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 20 Aug 2019 08:54:58 +0200 Subject: [PATCH 2/2] add whatsnew --- doc/source/whatsnew/v0.25.1.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 34b149a6b8261..3116d4be30cbf 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -105,6 +105,7 @@ I/O - Avoid calling ``S3File.s3`` when reading parquet, as this was removed in s3fs version 0.3.0 (:issue:`27756`) - Better error message when a negative header is passed in :func:`pandas.read_csv` (:issue:`27779`) +- Follow the ``min_rows`` display option (introduced in v0.25.0) correctly in the html repr in the notebook (:issue:`27991`). - Plotting