Skip to content

Commit 38761f6

Browse files
authored
DEPR: deprecated nonkeyword arguments in to_json (#54613)
deprecated nonkeyword arguments
1 parent 92f46fc commit 38761f6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Other API changes
9393
Deprecations
9494
~~~~~~~~~~~~
9595
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
96+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_json` except ``path_or_buf``. (:issue:`54229`)
9697
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_latex` except ``buf``. (:issue:`54229`)
9798
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_pickle` except ``path``. (:issue:`54229`)
9899
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_string` except ``buf``. (:issue:`54229`)

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,9 @@ def to_excel(
23522352
)
23532353

23542354
@final
2355+
@deprecate_nonkeyword_arguments(
2356+
version="3.0", allowed_args=["self", "path_or_buf"], name="to_json"
2357+
)
23552358
@doc(
23562359
storage_options=_shared_docs["storage_options"],
23572360
compression_options=_shared_docs["compression_options"] % "path_or_buf",

pandas/tests/io/json/test_pandas.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import datetime
22
from datetime import timedelta
33
from decimal import Decimal
4-
from io import StringIO
4+
from io import (
5+
BytesIO,
6+
StringIO,
7+
)
58
import json
69
import os
710
import sys
@@ -2106,3 +2109,15 @@ def test_json_roundtrip_string_inference(orient):
21062109
columns=pd.Index(["col 1", "col 2"], dtype=pd.ArrowDtype(pa.string())),
21072110
)
21082111
tm.assert_frame_equal(result, expected)
2112+
2113+
2114+
def test_json_pos_args_deprecation():
2115+
# GH-54229
2116+
df = DataFrame({"a": [1, 2, 3]})
2117+
msg = (
2118+
r"Starting with pandas version 3.0 all arguments of to_json except for the "
2119+
r"argument 'path_or_buf' will be keyword-only."
2120+
)
2121+
with tm.assert_produces_warning(FutureWarning, match=msg):
2122+
buf = BytesIO()
2123+
df.to_json(buf, "split")

0 commit comments

Comments
 (0)