Skip to content

Commit 2074948

Browse files
rmhowe425pmhatre1
authored andcommitted
DEPR: Positional arguments in Series.to_markdown (pandas-dev#57372)
* Updated whatsnew and added deprecation message. * Adding unit test for deprecation warning. * Updating unit tests. * Update series.py * Updating unit test and documentation. * Adding in to_markdown overload functions per reviewer feedback. * Updating implementation based on reviewer feedback.
1 parent b87edc7 commit 2074948

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Deprecations
102102
~~~~~~~~~~~~
103103
- Deprecated :meth:`Timestamp.utcfromtimestamp`, use ``Timestamp.fromtimestamp(ts, "UTC")`` instead (:issue:`56680`)
104104
- Deprecated :meth:`Timestamp.utcnow`, use ``Timestamp.now("UTC")`` instead (:issue:`56680`)
105+
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
105106
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
106107
-
107108

pandas/core/series.py

+39
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,42 @@ def to_string(
16061606
f.write(result)
16071607
return None
16081608

1609+
@overload
1610+
def to_markdown(
1611+
self,
1612+
buf: None = ...,
1613+
*,
1614+
mode: str = ...,
1615+
index: bool = ...,
1616+
storage_options: StorageOptions | None = ...,
1617+
**kwargs,
1618+
) -> str:
1619+
...
1620+
1621+
@overload
1622+
def to_markdown(
1623+
self,
1624+
buf: IO[str],
1625+
*,
1626+
mode: str = ...,
1627+
index: bool = ...,
1628+
storage_options: StorageOptions | None = ...,
1629+
**kwargs,
1630+
) -> None:
1631+
...
1632+
1633+
@overload
1634+
def to_markdown(
1635+
self,
1636+
buf: IO[str] | None,
1637+
*,
1638+
mode: str = ...,
1639+
index: bool = ...,
1640+
storage_options: StorageOptions | None = ...,
1641+
**kwargs,
1642+
) -> str | None:
1643+
...
1644+
16091645
@doc(
16101646
klass=_shared_doc_kwargs["klass"],
16111647
storage_options=_shared_docs["storage_options"],
@@ -1637,6 +1673,9 @@ def to_string(
16371673
+----+----------+"""
16381674
),
16391675
)
1676+
@deprecate_nonkeyword_arguments(
1677+
version="3.0.0", allowed_args=["self", "buf"], name="to_markdown"
1678+
)
16401679
def to_markdown(
16411680
self,
16421681
buf: IO[str] | None = None,

pandas/tests/io/formats/test_to_markdown.py

+12
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@
33
import pytest
44

55
import pandas as pd
6+
import pandas._testing as tm
67

78
pytest.importorskip("tabulate")
89

910

11+
def test_keyword_deprecation():
12+
# GH 57280
13+
msg = (
14+
"Starting with pandas version 3.0.0 all arguments of to_markdown "
15+
"except for the argument 'buf' will be keyword-only."
16+
)
17+
s = pd.Series()
18+
with tm.assert_produces_warning(FutureWarning, match=msg):
19+
s.to_markdown(None, "wt")
20+
21+
1022
def test_simple():
1123
buf = StringIO()
1224
df = pd.DataFrame([1, 2, 3])

0 commit comments

Comments
 (0)