diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 6ad6b5129ef5a..c978a1825a390 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -501,6 +501,7 @@ Deprecations - :func:`pandas.json_normalize` is now exposed in the top-level namespace. Usage of ``json_normalize`` as ``pandas.io.json.json_normalize`` is now deprecated and it is recommended to use ``json_normalize`` as :func:`pandas.json_normalize` instead (:issue:`27586`). +- The ``numpy`` argument of :meth:`pandas.read_json` is deprecated (:issue:`28512`). - .. _whatsnew_1000.prior_deprecations: diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 30c1c2d59e983..7e43a0eaca3e0 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -10,6 +10,7 @@ import pandas._libs.json as json from pandas._libs.tslibs import iNaT from pandas.errors import AbstractMethodError +from pandas.util._decorators import deprecate_kwarg from pandas.core.dtypes.common import ensure_str, is_period_dtype @@ -353,6 +354,7 @@ def _write( return serialized +@deprecate_kwarg(old_arg_name="numpy", new_arg_name=None) def read_json( path_or_buf=None, orient=None, @@ -466,6 +468,8 @@ def read_json( non-numeric column and index labels are supported. Note also that the JSON ordering MUST be the same for each term if numpy=True. + .. deprecated:: 1.0.0 + precise_float : bool, default False Set to enable usage of higher precision (strtod) function when decoding string to double values. Default (False) is to use fast but diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index bce3d1de849aa..ff18febca44d6 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -3,6 +3,7 @@ from io import StringIO import json import os +from warnings import catch_warnings, filterwarnings import numpy as np import pytest @@ -1601,3 +1602,13 @@ def test_json_indent_all_orients(self, orient, expected): def test_json_negative_indent_raises(self): with pytest.raises(ValueError, match="must be a nonnegative integer"): pd.DataFrame().to_json(indent=-1) + + @pytest.mark.filterwarnings("ignore:.*msgpack:FutureWarning") + def test_deprecate_numpy_argument_read_json(self): + # https://github.com/pandas-dev/pandas/issues/28512 + expected = DataFrame([1, 2, 3]) + with tm.assert_produces_warning(None): + with catch_warnings(): + filterwarnings("ignore", category=FutureWarning) + result = read_json(expected.to_json(), numpy=True) + tm.assert_frame_equal(result, expected)