Skip to content

Commit

Permalink
DEPR: deprecated nonkeyword arguments for to_string (#54597)
Browse files Browse the repository at this point in the history
* deprecated nonkeyword arguments

* added test
  • Loading branch information
rsm-23 authored Aug 17, 2023
1 parent 8335019 commit 77bc67a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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 @@ -95,6 +95,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_latex` except ``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)

0 comments on commit 77bc67a

Please sign in to comment.