Skip to content

Commit

Permalink
DEPR: Positional arguments in Series.to_string (pandas-dev#57375)
Browse files Browse the repository at this point in the history
* Adding deprecation, documentation, and unit test.

* Update series.py

* Updating unit tests.

* Updating implementation based on reviewer feedback.

* Updating implementation based on reviewer feedback.

* Updating implementation based on reviewer feedback.

* Updating implementation based on reviewer feedback.

* Updating implementation based on reviewer feedback.
  • Loading branch information
rmhowe425 authored Feb 17, 2024
1 parent 269f0b5 commit 63dc0f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit 63dc0f7

Please sign in to comment.