Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Deprecations
~~~~~~~~~~~~
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`)
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -1229,6 +1230,9 @@ def to_string(
) -> None:
...

@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "buf"], name="to_string"
)
@Substitution(
header_type="bool or list of str",
header="Write out the column names. If a list of columns "
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/io/formats/test_to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
option_context,
to_datetime,
)
import pandas._testing as tm


def test_repr_embedded_ndarray():
Expand Down Expand Up @@ -355,3 +356,15 @@ def test_to_string_string_dtype():
z int64[pyarrow]"""
)
assert result == expected


def test_to_string_pos_args_deprecation():
# GH-54229
df = DataFrame({"a": [1, 2, 3]})
msg = (
r"Starting with pandas version 3.0 all arguments of to_string except for the "
r"argument 'buf' will be keyword-only."
)
with tm.assert_produces_warning(FutureWarning, match=msg):
buf = StringIO()
df.to_string(buf, None, None, True, True)