Skip to content

Commit 7ff13b4

Browse files
authored
DEPR: Nonkeyword arguments in to_pickle (#54599)
* deprecated non keyword arguments * addressed review comments
1 parent cf7f0af commit 7ff13b4

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v2.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Other API changes
9292

9393
Deprecations
9494
~~~~~~~~~~~~
95-
-
95+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`)
9696
-
9797

9898
.. ---------------------------------------------------------------------------

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,9 @@ def to_sql(
30173017
)
30183018

30193019
@final
3020+
@deprecate_nonkeyword_arguments(
3021+
version="3.0", allowed_args=["self", "path"], name="to_pickle"
3022+
)
30203023
@doc(
30213024
storage_options=_shared_docs["storage_options"],
30223025
compression_options=_shared_docs["compression_options"] % "path",

pandas/tests/io/test_pickle.py

+12
Original file line numberDiff line numberDiff line change
@@ -585,3 +585,15 @@ def test_pickle_frame_v124_unpickle_130(datapath):
585585

586586
expected = pd.DataFrame(index=[], columns=[])
587587
tm.assert_frame_equal(df, expected)
588+
589+
590+
def test_pickle_pos_args_deprecation():
591+
# GH-54229
592+
df = pd.DataFrame({"a": [1, 2, 3]})
593+
msg = (
594+
r"Starting with pandas version 3.0 all arguments of to_pickle except for the "
595+
r"argument 'path' will be keyword-only."
596+
)
597+
with tm.assert_produces_warning(FutureWarning, match=msg):
598+
buffer = io.BytesIO()
599+
df.to_pickle(buffer, "infer")

0 commit comments

Comments
 (0)