From 1270d21b8ae043a63af2d9dc57092bc94e4c23da Mon Sep 17 00:00:00 2001 From: rajatsmukherjee Date: Thu, 17 Aug 2023 13:36:13 +0530 Subject: [PATCH 1/3] added nonkeyword deprecation --- pandas/core/generic.py | 3 +++ 1 file changed, 3 insertions(+) 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", From e5a2918f880c567f1e57e596a7aa04374cd6e07e Mon Sep 17 00:00:00 2001 From: rajatsmukherjee Date: Thu, 17 Aug 2023 14:02:09 +0530 Subject: [PATCH 2/3] added whatsnew --- doc/source/whatsnew/v2.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 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`) - .. --------------------------------------------------------------------------- From d5e03492d1faa190e6b2ac969d3a8ff560366f5d Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Thu, 17 Aug 2023 09:49:17 +0000 Subject: [PATCH 3/3] added unittest --- pandas/tests/generic/test_generic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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")