Skip to content

Commit 533d322

Browse files
rsm-23mroeschke
authored andcommitted
DEPR: deprecated nonkeyword arguments for to_string (pandas-dev#54597)
* deprecated nonkeyword arguments * added test
1 parent e7ab43f commit 533d322

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Deprecations
9595
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
9696
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`)
9797
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`)
98+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`)
9899
-
99100

100101
.. ---------------------------------------------------------------------------

pandas/core/frame.py

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
from pandas.util._decorators import (
6565
Appender,
6666
Substitution,
67+
deprecate_nonkeyword_arguments,
6768
doc,
6869
)
6970
from pandas.util._exceptions import find_stack_level
@@ -1229,6 +1230,9 @@ def to_string(
12291230
) -> None:
12301231
...
12311232

1233+
@deprecate_nonkeyword_arguments(
1234+
version="3.0", allowed_args=["self", "buf"], name="to_string"
1235+
)
12321236
@Substitution(
12331237
header_type="bool or list of str",
12341238
header="Write out the column names. If a list of columns "

pandas/tests/io/formats/test_to_string.py

+13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
option_context,
1212
to_datetime,
1313
)
14+
import pandas._testing as tm
1415

1516

1617
def test_repr_embedded_ndarray():
@@ -355,3 +356,15 @@ def test_to_string_string_dtype():
355356
z int64[pyarrow]"""
356357
)
357358
assert result == expected
359+
360+
361+
def test_to_string_pos_args_deprecation():
362+
# GH-54229
363+
df = DataFrame({"a": [1, 2, 3]})
364+
msg = (
365+
r"Starting with pandas version 3.0 all arguments of to_string except for the "
366+
r"argument 'buf' will be keyword-only."
367+
)
368+
with tm.assert_produces_warning(FutureWarning, match=msg):
369+
buf = StringIO()
370+
df.to_string(buf, None, None, True, True)

0 commit comments

Comments
 (0)