Skip to content

Commit dc18c57

Browse files
rsm-23mroeschke
authored andcommitted
DEPR: deprecated nonkeyword arguments in to_markdown (pandas-dev#54605)
* deprecated nonkeyword arguments * added parameter keywords
1 parent 3d087ff commit dc18c57

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Deprecations
9595
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
9696
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_json` except ``path_or_buf``. (:issue:`54229`)
9797
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`)
98+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_markdown` except ``buf``. (:issue:`54229`)
9899
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`)
99100
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`)
100101
-

pandas/core/frame.py

+3
Original file line numberDiff line numberDiff line change
@@ -2800,6 +2800,9 @@ def to_feather(self, path: FilePath | WriteBuffer[bytes], **kwargs) -> None:
28002800

28012801
to_feather(self, path, **kwargs)
28022802

2803+
@deprecate_nonkeyword_arguments(
2804+
version="3.0", allowed_args=["self", "buf"], name="to_markdown"
2805+
)
28032806
@doc(
28042807
Series.to_markdown,
28052808
klass=_shared_doc_kwargs["klass"],

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ def to_markdown(
18711871
{examples}
18721872
"""
18731873
return self.to_frame().to_markdown(
1874-
buf, mode, index, storage_options=storage_options, **kwargs
1874+
buf, mode=mode, index=index, storage_options=storage_options, **kwargs
18751875
)
18761876

18771877
# ----------------------------------------------------------------------

pandas/tests/io/formats/test_to_markdown.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
from io import StringIO
1+
from io import (
2+
BytesIO,
3+
StringIO,
4+
)
25

36
import pytest
47

58
import pandas as pd
9+
import pandas._testing as tm
610

711
pytest.importorskip("tabulate")
812

@@ -88,3 +92,15 @@ def test_showindex_disallowed_in_kwargs():
8892
df = pd.DataFrame([1, 2, 3])
8993
with pytest.raises(ValueError, match="Pass 'index' instead of 'showindex"):
9094
df.to_markdown(index=True, showindex=True)
95+
96+
97+
def test_markdown_pos_args_deprecatation():
98+
# GH-54229
99+
df = pd.DataFrame({"a": [1, 2, 3]})
100+
msg = (
101+
r"Starting with pandas version 3.0 all arguments of to_markdown except for the "
102+
r"argument 'buf' will be keyword-only."
103+
)
104+
with tm.assert_produces_warning(FutureWarning, match=msg):
105+
buffer = BytesIO()
106+
df.to_markdown(buffer, "grid")

0 commit comments

Comments
 (0)