From fd239855c38462d7e327c3fa8f20d6a33413a37f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 12 Jun 2019 19:10:36 +0100 Subject: [PATCH 1/4] DEPR: deprecate notebook argument in DataFrame.to_html() --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/frame.py | 11 +++++++++-- pandas/tests/io/formats/test_to_html.py | 10 ++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 6d850095510d0..5ceed71fea28e 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -495,7 +495,7 @@ Other Deprecations Use the public attributes :attr:`~RangeIndex.start`, :attr:`~RangeIndex.stop` and :attr:`~RangeIndex.step` instead (:issue:`26581`). - The :meth:`Series.ftype`, :meth:`Series.ftypes` and :meth:`DataFrame.ftypes` methods are deprecated and will be removed in a future version. Instead, use :meth:`Series.dtype` and :meth:`DataFrame.dtypes` (:issue:`26705`). - +- The ``notebook`` argument of :meth:`DataFrame.to_html` is deprecated (:issue:`23820`). .. _whatsnew_0250.prior_deprecations: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ef406ce3d6b02..73527fc50c32f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -650,8 +650,11 @@ def _repr_html_(self): max_cols = get_option("display.max_columns") show_dimensions = get_option("display.show_dimensions") - return self.to_html(max_rows=max_rows, max_cols=max_cols, - show_dimensions=show_dimensions, notebook=True) + formatter = fmt.DataFrameFormatter( + self, max_rows=max_rows, max_cols=max_cols, + show_dimensions=show_dimensions) + formatter.to_html(notebook=True) + return formatter.buf.getvalue() else: return None @@ -2141,6 +2144,7 @@ def to_parquet(self, fname, engine='auto', compression='snappy', ' Abillity to use str') @Substitution(shared_params=fmt.common_docstring, returns=fmt.return_docstring) + @deprecate_kwarg(old_arg_name="notebook", new_arg_name=None) def to_html(self, buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=None, index_names=True, justify=None, max_rows=None, @@ -2158,6 +2162,9 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True, Convert the characters <, >, and & to HTML-safe sequences. notebook : {True, False}, default False Whether the generated HTML is for IPython Notebook. + + .. deprecated:: 0.25.0 + border : int A ``border=border`` attribute is included in the opening `` tag. Default ``pd.options.display.html.border``. diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 97d51f079fb2d..9a22d9cde48a3 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -542,7 +542,8 @@ def test_to_html_truncation_index_false_max_cols( @pytest.mark.parametrize('notebook', [True, False]) def test_to_html_notebook_has_style(notebook): df = DataFrame({"A": [1, 2, 3]}) - result = df.to_html(notebook=notebook) + with tm.assert_produces_warning(FutureWarning): + result = df.to_html(notebook=notebook) if notebook: assert "tbody tr th:only-of-type" in result @@ -627,9 +628,10 @@ def test_to_html_invalid_classes_type(classes): def test_to_html_round_column_headers(): # GH 17280 df = DataFrame([1], columns=[0.55555]) - with pd.option_context('display.precision', 3): - html = df.to_html(notebook=False) - notebook = df.to_html(notebook=True) + with tm.assert_produces_warning(FutureWarning): + with pd.option_context('display.precision', 3): + html = df.to_html(notebook=False) + notebook = df.to_html(notebook=True) assert "0.55555" in html assert "0.556" in notebook From 271a3295a7d493b2ff9fe54790e97852bb87ef9a Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 24 Aug 2019 12:32:51 +0100 Subject: [PATCH 2/4] whatsnew --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 8e25857e5ad69..9ffa0101984fd 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -54,7 +54,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- The ``notebook`` argument of :meth:`DataFrame.to_html` is deprecated (:issue:`23820`). - .. _whatsnew_1000.prior_deprecations: From 9daa62b12cdb5bb5311b60940245c011c2b4dd27 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 24 Aug 2019 13:05:58 +0100 Subject: [PATCH 3/4] format black --- pandas/tests/io/formats/test_to_html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 73599435541cc..9699c34a21c63 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -696,7 +696,7 @@ def test_to_html_round_column_headers(): # GH 17280 df = DataFrame([1], columns=[0.55555]) with tm.assert_produces_warning(FutureWarning): - with pd.option_context('display.precision', 3): + with pd.option_context("display.precision", 3): html = df.to_html(notebook=False) notebook = df.to_html(notebook=True) assert "0.55555" in html From 97dd413b9ee23b49ca81caa67b0f2df3c385e0d2 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 30 Aug 2019 16:19:30 +0100 Subject: [PATCH 4/4] update .. deprecated:: --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1f4014bd496db..3fa90f042999d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2247,7 +2247,7 @@ def to_html( notebook : {True, False}, default False Whether the generated HTML is for IPython Notebook. - .. deprecated:: 0.25.0 + .. deprecated:: 1.0.0 border : int A ``border=border`` attribute is included in the opening