From e04e1f787705fb7b4cb64408bfcbb5ddb52213b3 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Thu, 17 Aug 2023 10:43:14 +0000 Subject: [PATCH 1/2] deprecated non keyword arguments --- doc/source/whatsnew/v2.2.0.rst | 2 +- pandas/core/generic.py | 3 +++ pandas/tests/generic/test_generic.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index c35473b852eb9..9295ad6cb9aa6 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -92,7 +92,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7624c8f7c7930..88fa32ca5b20b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3017,6 +3017,9 @@ def to_sql( ) @final + @deprecate_nonkeyword_arguments( + version=None, allowed_args=["self", "path"], name="to_pickle" + ) @doc( storage_options=_shared_docs["storage_options"], compression_options=_shared_docs["compression_options"] % "path", diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 87beab04bc586..7b5b31037d445 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -460,3 +460,13 @@ def test_bool_dep(self) -> None: ) with tm.assert_produces_warning(FutureWarning, match=msg_warn): DataFrame({"col": [False]}).bool() + + def test_drop_pos_args_deprecation_for_to_pickle(self): + # GH-54229 + df = DataFrame({"a": [1, 2, 3]}) + msg = ( + r"In a future version of pandas all arguments of to_pickle " + r"except for the argument 'path' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df.to_pickle("./dummy.pkl", "infer") From 6790da32eca039ca06a049f5a09d9ea984341f9e Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Thu, 17 Aug 2023 16:18:28 +0000 Subject: [PATCH 2/2] addressed review comments --- pandas/core/generic.py | 2 +- pandas/tests/generic/test_generic.py | 10 ---------- pandas/tests/io/test_pickle.py | 12 ++++++++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 88fa32ca5b20b..8b1540efcef54 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3018,7 +3018,7 @@ def to_sql( @final @deprecate_nonkeyword_arguments( - version=None, allowed_args=["self", "path"], name="to_pickle" + version="3.0", allowed_args=["self", "path"], name="to_pickle" ) @doc( storage_options=_shared_docs["storage_options"], diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 7b5b31037d445..87beab04bc586 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -460,13 +460,3 @@ def test_bool_dep(self) -> None: ) with tm.assert_produces_warning(FutureWarning, match=msg_warn): DataFrame({"col": [False]}).bool() - - def test_drop_pos_args_deprecation_for_to_pickle(self): - # GH-54229 - df = DataFrame({"a": [1, 2, 3]}) - msg = ( - r"In a future version of pandas all arguments of to_pickle " - r"except for the argument 'path' will be keyword-only" - ) - with tm.assert_produces_warning(FutureWarning, match=msg): - df.to_pickle("./dummy.pkl", "infer") diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index 75e4de7074e63..a30b3f64bd75c 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -585,3 +585,15 @@ def test_pickle_frame_v124_unpickle_130(datapath): expected = pd.DataFrame(index=[], columns=[]) tm.assert_frame_equal(df, expected) + + +def test_pickle_pos_args_deprecation(): + # GH-54229 + df = pd.DataFrame({"a": [1, 2, 3]}) + msg = ( + r"Starting with pandas version 3.0 all arguments of to_pickle except for the " + r"argument 'path' will be keyword-only." + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + buffer = io.BytesIO() + df.to_pickle(buffer, "infer")