Skip to content

Commit 258d31c

Browse files
rmhowe425pmhatre1
authored andcommitted
DEPR: Positional arguments in Series.to_string (pandas-dev#57375)
* 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.
1 parent bb77d11 commit 258d31c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-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_string` except ``buf``. (:issue:`57280`)
105106
-
106107

107108
.. ---------------------------------------------------------------------------

pandas/core/series.py

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from pandas.util._decorators import (
4747
Appender,
4848
Substitution,
49+
deprecate_nonkeyword_arguments,
4950
doc,
5051
)
5152
from pandas.util._exceptions import find_stack_level
@@ -1488,6 +1489,7 @@ def __repr__(self) -> str:
14881489
def to_string(
14891490
self,
14901491
buf: None = ...,
1492+
*,
14911493
na_rep: str = ...,
14921494
float_format: str | None = ...,
14931495
header: bool = ...,
@@ -1504,6 +1506,7 @@ def to_string(
15041506
def to_string(
15051507
self,
15061508
buf: FilePath | WriteBuffer[str],
1509+
*,
15071510
na_rep: str = ...,
15081511
float_format: str | None = ...,
15091512
header: bool = ...,
@@ -1516,6 +1519,9 @@ def to_string(
15161519
) -> None:
15171520
...
15181521

1522+
@deprecate_nonkeyword_arguments(
1523+
version="3.0.0", allowed_args=["self", "buf"], name="to_string"
1524+
)
15191525
def to_string(
15201526
self,
15211527
buf: FilePath | WriteBuffer[str] | None = None,

pandas/tests/io/formats/test_to_string.py

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ def _three_digit_exp():
3535

3636

3737
class TestDataFrameToStringFormatters:
38+
def test_keyword_deprecation(self):
39+
# GH 57280
40+
msg = (
41+
"Starting with pandas version 3.0.0 all arguments of to_string "
42+
"except for the argument 'buf' will be keyword-only."
43+
)
44+
s = Series(["a", "b"])
45+
with tm.assert_produces_warning(FutureWarning, match=msg):
46+
s.to_string(None, "NaN")
47+
3848
def test_to_string_masked_ea_with_formatter(self):
3949
# GH#39336
4050
df = DataFrame(

0 commit comments

Comments
 (0)