diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 77c80dcfe7c7e..4620de570e230 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -102,6 +102,7 @@ Deprecations ~~~~~~~~~~~~ - Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`) - Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`) +- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`) - Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`) - diff --git a/pandas/core/series.py b/pandas/core/series.py index 27ae5d3a8596d..ed82a62d0f345 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1606,6 +1606,42 @@ def to_string( f.write(result) return None + @overload + def to_markdown( + self, + buf: None = ..., + *, + mode: str = ..., + index: bool = ..., + storage_options: StorageOptions | None = ..., + **kwargs, + ) -> str: + ... + + @overload + def to_markdown( + self, + buf: IO[str], + *, + mode: str = ..., + index: bool = ..., + storage_options: StorageOptions | None = ..., + **kwargs, + ) -> None: + ... + + @overload + def to_markdown( + self, + buf: IO[str] | None, + *, + mode: str = ..., + index: bool = ..., + storage_options: StorageOptions | None = ..., + **kwargs, + ) -> str | None: + ... + @doc( klass=_shared_doc_kwargs["klass"], storage_options=_shared_docs["storage_options"], @@ -1637,6 +1673,9 @@ def to_string( +----+----------+""" ), ) + @deprecate_nonkeyword_arguments( + version="3.0.0", allowed_args=["self", "buf"], name="to_markdown" + ) def to_markdown( self, buf: IO[str] | None = None, diff --git a/pandas/tests/io/formats/test_to_markdown.py b/pandas/tests/io/formats/test_to_markdown.py index 437f079c5f2f9..fffb1b9b9d2a4 100644 --- a/pandas/tests/io/formats/test_to_markdown.py +++ b/pandas/tests/io/formats/test_to_markdown.py @@ -3,10 +3,22 @@ import pytest import pandas as pd +import pandas._testing as tm pytest.importorskip("tabulate") +def test_keyword_deprecation(): + # GH 57280 + msg = ( + "Starting with pandas version 3.0.0 all arguments of to_markdown " + "except for the argument 'buf' will be keyword-only." + ) + s = pd.Series() + with tm.assert_produces_warning(FutureWarning, match=msg): + s.to_markdown(None, "wt") + + def test_simple(): buf = StringIO() df = pd.DataFrame([1, 2, 3])