Skip to content

Commit

Permalink
DEPR: deprecated nonkeyword arguments in to_markdown (pandas-dev#54605)
Browse files Browse the repository at this point in the history
* deprecated nonkeyword arguments

* added parameter keywords
  • Loading branch information
rsm-23 authored and mroeschke committed Aug 18, 2023
1 parent 3d087ff commit dc18c57
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
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 @@ -95,6 +95,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_json` 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")

0 comments on commit dc18c57

Please sign in to comment.