From de5105efc1f0c98f511ec04314d691375e4b32ad Mon Sep 17 00:00:00 2001 From: linus-md Date: Tue, 19 Dec 2023 14:33:55 +0100 Subject: [PATCH 1/2] DOC: Add example using ``dtype_backend="numpy_nullable"`` to ``read_json()`` --- pandas/io/json/_json.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 9c56089560507..fca8048e69aba 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -763,6 +763,20 @@ def read_json( {{"index":"row 2","col 1":"c","col 2":"d"}}]\ }}\ ' + + The following example uses ``dtype_backend="numpy_nullable"`` + + >>> data = '''{{"index": {{"0": 0, "1": 1}}, + ... "a": {{"0": 1, "1": null}}, + ... "b": {{"0": 2.5, "1": 4.5}}, + ... "c": {{"0": true, "1": false}}, + ... "d": {{"0": "a", "1": "b"}}, + ... "e": {{"0": 1577.2, "1": 1577.1}}}}''' + >>> df = pd.read_json(StringIO(data), dtype_backend="numpy_nullable") + >>> print(df) + index a b c d e + 0 0 1 2.5 True a 1577.2 + 1 1 4.5 False b 1577.1 """ if orient == "table" and dtype: raise ValueError("cannot pass both dtype and orient='table'") From 4027d67e683ac636ccf755988fa16ee4f8335515 Mon Sep 17 00:00:00 2001 From: Linus Sommer <95619282+linus-md@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:51:05 +0100 Subject: [PATCH 2/2] Update pandas/io/json/_json.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/io/json/_json.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index fca8048e69aba..5ef354fc70c5c 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -772,8 +772,7 @@ def read_json( ... "c": {{"0": true, "1": false}}, ... "d": {{"0": "a", "1": "b"}}, ... "e": {{"0": 1577.2, "1": 1577.1}}}}''' - >>> df = pd.read_json(StringIO(data), dtype_backend="numpy_nullable") - >>> print(df) + >>> pd.read_json(StringIO(data), dtype_backend="numpy_nullable") index a b c d e 0 0 1 2.5 True a 1577.2 1 1 4.5 False b 1577.1