diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index d520aacf3e85c..af224b277d87d 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_latex` except ``buf``. (:issue:`54229`) - Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`) - diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 56a60f5d1a38c..c28ae86985896 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3306,6 +3306,9 @@ def to_latex( ... @final + @deprecate_nonkeyword_arguments( + version="3.0", allowed_args=["self", "buf"], name="to_latex" + ) def to_latex( self, buf: FilePath | WriteBuffer[str] | None = None, 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):