From 796e594e365cd713e4fdcc5151802716009a161e Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Fri, 18 Aug 2023 05:32:48 +0000 Subject: [PATCH] deprecated nonkeyword arguments --- doc/source/whatsnew/v2.2.0.rst | 1 + pandas/core/frame.py | 3 +++ pandas/tests/io/formats/test_to_html.py | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 4ad450c965464..1757bc3001385 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -93,6 +93,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`) +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_html` except ``buf``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1e10e8f11a575..dc062f947b695 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3134,6 +3134,9 @@ def to_html( ) -> str: ... + @deprecate_nonkeyword_arguments( + version="3.0", allowed_args=["self", "buf"], name="to_html" + ) @Substitution( header_type="bool", header="Whether to print column labels, default True", diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 3b5fe329c320c..5811485406b86 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -978,3 +978,14 @@ def test_to_html_empty_complex_array(): "" ) assert result == expected + + +def test_to_html_pos_args_deprecation(): + # GH-54229 + df = DataFrame({"a": [1, 2, 3]}) + msg = ( + r"Starting with pandas version 3.0 all arguments of to_html except for the " + r"argument 'buf' will be keyword-only." + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df.to_html(None, None)