Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: Positional arguments in Series.to_string #57375

Merged
merged 9 commits into from
Feb 17, 2024
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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_string` except ``buf``. (:issue:`57280`)
-

.. ---------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -1488,6 +1489,7 @@ def __repr__(self) -> str:
def to_string(
self,
buf: None = ...,
*,
na_rep: str = ...,
float_format: str | None = ...,
header: bool = ...,
Expand All @@ -1504,6 +1506,7 @@ def to_string(
def to_string(
self,
buf: FilePath | WriteBuffer[str],
*,
na_rep: str = ...,
float_format: str | None = ...,
header: bool = ...,
Expand All @@ -1516,6 +1519,9 @@ def to_string(
) -> None:
...

@deprecate_nonkeyword_arguments(
version="3.0.0", allowed_args=["self", "buf"], name="to_string"
)
def to_string(
self,
buf: FilePath | WriteBuffer[str] | None = None,
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/io/formats/test_to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def _three_digit_exp():


class TestDataFrameToStringFormatters:
def test_keyword_deprecation(self):
# GH 57280
msg = (
"Starting with pandas version 3.0.0 all arguments of to_string "
"except for the argument 'buf' will be keyword-only."
)
s = Series(["a", "b"])
with tm.assert_produces_warning(FutureWarning, match=msg):
s.to_string(None, "NaN")

def test_to_string_masked_ea_with_formatter(self):
# GH#39336
df = DataFrame(
Expand Down