Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ 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_markdown` 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`)
-
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,9 @@ def to_feather(self, path: FilePath | WriteBuffer[bytes], **kwargs) -> None:

to_feather(self, path, **kwargs)

@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "buf"], name="to_markdown"
)
@doc(
Series.to_markdown,
klass=_shared_doc_kwargs["klass"],
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ def to_markdown(
{examples}
"""
return self.to_frame().to_markdown(
buf, mode, index, storage_options=storage_options, **kwargs
buf, mode=mode, index=index, storage_options=storage_options, **kwargs
)

# ----------------------------------------------------------------------
Expand Down
18 changes: 17 additions & 1 deletion pandas/tests/io/formats/test_to_markdown.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from io import StringIO
from io import (
BytesIO,
StringIO,
)

import pytest

import pandas as pd
import pandas._testing as tm

pytest.importorskip("tabulate")

Expand Down Expand Up @@ -88,3 +92,15 @@ def test_showindex_disallowed_in_kwargs():
df = pd.DataFrame([1, 2, 3])
with pytest.raises(ValueError, match="Pass 'index' instead of 'showindex"):
df.to_markdown(index=True, showindex=True)


def test_markdown_pos_args_deprecatation():
# GH-54229
df = pd.DataFrame({"a": [1, 2, 3]})
msg = (
r"Starting with pandas version 3.0 all arguments of to_markdown except for the "
r"argument 'buf' will be keyword-only."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
buffer = BytesIO()
df.to_markdown(buffer, "grid")