From 6ad68ce8f30ab15c6c4e2e76e338b2ea8d878f79 Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Sun, 11 Feb 2024 23:01:27 -0500 Subject: [PATCH 1/8] Adding deprecation, documentation, and unit test. --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/core/series.py | 3 +++ pandas/tests/io/formats/test_to_string.py | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index aa378faac2a00..ba0ccffc61b0b 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -96,6 +96,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`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/series.py b/pandas/core/series.py index d5eaa2125b301..db06e598e46fe 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1517,6 +1517,9 @@ def to_string( ) -> None: ... + @deprecate_nonkeyword_arguments( + version="3.0.1", allowed_args=["self", "buf"], name="to_string" + ) def to_string( self, buf: FilePath | WriteBuffer[str] | None = None, diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index f91f46c8460c4..45fe6b41a0872 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -35,6 +35,16 @@ def _three_digit_exp(): class TestDataFrameToStringFormatters: + def test_keyword_deprecation(self): + # GH 57280 + msg = ( + "Starting with pandas version 3.0.1 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( From b886ae282f1bd0402aa63d8badfb80b85e6b66b7 Mon Sep 17 00:00:00 2001 From: Richard Howe <45905457+rmhowe425@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:13:57 -0500 Subject: [PATCH 2/8] Update series.py --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index db06e598e46fe..ecb0e2b130f5a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1518,7 +1518,7 @@ def to_string( ... @deprecate_nonkeyword_arguments( - version="3.0.1", allowed_args=["self", "buf"], name="to_string" + version="3.0.0", allowed_args=["self", "buf"], name="to_string" ) def to_string( self, From 7c1d0b0522c165d5000d87ddcf05dd9a2f9fa20f Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Mon, 12 Feb 2024 22:58:27 -0500 Subject: [PATCH 3/8] Updating unit tests. --- pandas/tests/io/formats/test_to_string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index 45fe6b41a0872..7c7069aa74eeb 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -38,7 +38,7 @@ class TestDataFrameToStringFormatters: def test_keyword_deprecation(self): # GH 57280 msg = ( - "Starting with pandas version 3.0.1 all arguments of to_string " + "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"]) From 8b4271a38cc189241667f5107c046a9309431388 Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Fri, 16 Feb 2024 20:46:48 -0500 Subject: [PATCH 4/8] Updating implementation based on reviewer feedback. --- pandas/core/series.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index ecb0e2b130f5a..458426ce39893 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1486,6 +1486,9 @@ def __repr__(self) -> str: return self.to_string(**repr_params) @overload + @deprecate_nonkeyword_arguments( + version="3.0.0", allowed_args=["self", "buf"], name="to_string" + ) def to_string( self, buf: None = ..., @@ -1502,6 +1505,9 @@ def to_string( ... @overload + @deprecate_nonkeyword_arguments( + version="3.0.0", allowed_args=["self", "buf"], name="to_string" + ) def to_string( self, buf: FilePath | WriteBuffer[str], From 93e1dd424d3c49d41159836f52de08596fca05b0 Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Fri, 16 Feb 2024 21:05:33 -0500 Subject: [PATCH 5/8] Updating implementation based on reviewer feedback. --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 458426ce39893..3d077614e3693 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1485,10 +1485,10 @@ def __repr__(self) -> str: repr_params = fmt.get_series_repr_params() return self.to_string(**repr_params) - @overload @deprecate_nonkeyword_arguments( version="3.0.0", allowed_args=["self", "buf"], name="to_string" ) + @overload def to_string( self, buf: None = ..., @@ -1504,10 +1504,10 @@ def to_string( ) -> str: ... - @overload @deprecate_nonkeyword_arguments( version="3.0.0", allowed_args=["self", "buf"], name="to_string" ) + @overload def to_string( self, buf: FilePath | WriteBuffer[str], From e1810dd91bf808cb5e97d0f0404e79024db531b5 Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Fri, 16 Feb 2024 21:11:29 -0500 Subject: [PATCH 6/8] Updating implementation based on reviewer feedback. --- pandas/core/series.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 3d077614e3693..ecb0e2b130f5a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1485,9 +1485,6 @@ def __repr__(self) -> str: repr_params = fmt.get_series_repr_params() return self.to_string(**repr_params) - @deprecate_nonkeyword_arguments( - version="3.0.0", allowed_args=["self", "buf"], name="to_string" - ) @overload def to_string( self, @@ -1504,9 +1501,6 @@ def to_string( ) -> str: ... - @deprecate_nonkeyword_arguments( - version="3.0.0", allowed_args=["self", "buf"], name="to_string" - ) @overload def to_string( self, From 5bd52b32933fa38d0eca45ad555011eb3a68680c Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Fri, 16 Feb 2024 22:43:48 -0500 Subject: [PATCH 7/8] Updating implementation based on reviewer feedback. --- pandas/core/series.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index 227cfd4c301f5..1497eb0455194 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1488,6 +1488,7 @@ def __repr__(self) -> str: def to_string( self, buf: None = ..., + *, na_rep: str = ..., float_format: str | None = ..., header: bool = ..., @@ -1504,6 +1505,7 @@ def to_string( def to_string( self, buf: FilePath | WriteBuffer[str], + *, na_rep: str = ..., float_format: str | None = ..., header: bool = ..., From c4024cd052c077440f0ce15b10616b5a066b335c Mon Sep 17 00:00:00 2001 From: Richard Howe Date: Fri, 16 Feb 2024 22:56:14 -0500 Subject: [PATCH 8/8] Updating implementation based on reviewer feedback. --- pandas/core/series.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index 1497eb0455194..27ae5d3a8596d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -46,6 +46,7 @@ from pandas.util._decorators import ( Appender, Substitution, + deprecate_nonkeyword_arguments, doc, ) from pandas.util._exceptions import find_stack_level