From 3e1da69beb89fe98473b95330bf6d146f45b6f64 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Thu, 17 Aug 2023 10:48:19 +0000 Subject: [PATCH 1/3] deprecated non keyword arguments --- doc/source/whatsnew/v2.2.0.rst | 2 +- pandas/core/generic.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index c35473b852eb9..f5645191293dc 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -92,7 +92,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``buf``. (:issue:`54229`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7624c8f7c7930..9d4cb76c39ef7 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3300,6 +3300,9 @@ def to_latex( ... @final + @deprecate_nonkeyword_arguments( + version=None, allowed_args=["self", "buf"], name="to_latex" + ) def to_latex( self, buf: FilePath | WriteBuffer[str] | None = None, From 582b726e30369f3622b43c2b4c525041e63342fe Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Thu, 17 Aug 2023 12:06:57 +0000 Subject: [PATCH 2/3] fixed typo --- doc/source/whatsnew/v2.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index f5645191293dc..f431aa758ecc2 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -92,7 +92,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``buf``. (:issue:`54229`) +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`) - .. --------------------------------------------------------------------------- From 6e4236c12652a62f1f9938e1308bfec330bf1259 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Thu, 17 Aug 2023 17:26:17 +0000 Subject: [PATCH 3/3] added test --- pandas/core/generic.py | 2 +- pandas/tests/io/formats/test_to_latex.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9d4cb76c39ef7..2d8e1fe15bb3c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3301,7 +3301,7 @@ def to_latex( @final @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "buf"], name="to_latex" + version="3.0", allowed_args=["self", "buf"], name="to_latex" ) def to_latex( self, diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index d715daf253cd3..1fd96dff27d06 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -187,6 +187,22 @@ def test_to_latex_midrule_location(self): ) assert result == expected + def test_to_latex_pos_args_deprecation(self): + # GH-54229 + df = DataFrame( + { + "name": ["Raphael", "Donatello"], + "age": [26, 45], + "height": [181.23, 177.65], + } + ) + msg = ( + r"Starting with pandas version 3.0 all arguments of to_latex except for " + r"the argument 'buf' will be keyword-only." + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df.to_latex(None, None) + class TestToLatexLongtable: def test_to_latex_empty_longtable(self):