Skip to content

Commit 4fb264a

Browse files
alimcmaster1jreback
authored andcommitted
DEPR: Deprecate numpy argument in read_json (#30636)
1 parent 0721841 commit 4fb264a

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

doc/source/user_guide/io.rst

+4
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,8 @@ The Numpy parameter
20662066
+++++++++++++++++++
20672067

20682068
.. note::
2069+
This param has been deprecated as of version 1.0.0 and will raise a ``FutureWarning``.
2070+
20692071
This supports numeric data only. Index and columns labels may be non-numeric, e.g. strings, dates etc.
20702072

20712073
If ``numpy=True`` is passed to ``read_json`` an attempt will be made to sniff
@@ -2088,6 +2090,7 @@ data:
20882090
%timeit pd.read_json(jsonfloats)
20892091
20902092
.. ipython:: python
2093+
:okwarning:
20912094
20922095
%timeit pd.read_json(jsonfloats, numpy=True)
20932096
@@ -2102,6 +2105,7 @@ The speedup is less noticeable for smaller datasets:
21022105
%timeit pd.read_json(jsonfloats)
21032106
21042107
.. ipython:: python
2108+
:okwarning:
21052109
21062110
%timeit pd.read_json(jsonfloats, numpy=True)
21072111

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ Deprecations
607607
- :func:`pandas.json_normalize` is now exposed in the top-level namespace.
608608
Usage of ``json_normalize`` as ``pandas.io.json.json_normalize`` is now deprecated and
609609
it is recommended to use ``json_normalize`` as :func:`pandas.json_normalize` instead (:issue:`27586`).
610+
- The ``numpy`` argument of :meth:`pandas.read_json` is deprecated (:issue:`28512`).
610611
- :meth:`DataFrame.to_stata`, :meth:`DataFrame.to_feather`, and :meth:`DataFrame.to_parquet` argument "fname" is deprecated, use "path" instead (:issue:`23574`)
611612
- The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`)
612613
- The ``pandas.util.testing`` module has been deprecated. Use the public API in ``pandas.testing`` documented at :ref:`api.general.testing` (:issue:`16232`).

pandas/io/json/_json.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pandas._libs.tslibs import iNaT
1212
from pandas._typing import JSONSerializable
1313
from pandas.errors import AbstractMethodError
14+
from pandas.util._decorators import deprecate_kwarg
1415

1516
from pandas.core.dtypes.common import ensure_str, is_period_dtype
1617

@@ -345,6 +346,7 @@ def _write(
345346
return serialized
346347

347348

349+
@deprecate_kwarg(old_arg_name="numpy", new_arg_name=None)
348350
def read_json(
349351
path_or_buf=None,
350352
orient=None,
@@ -458,6 +460,8 @@ def read_json(
458460
non-numeric column and index labels are supported. Note also that the
459461
JSON ordering MUST be the same for each term if numpy=True.
460462
463+
.. deprecated:: 1.0.0
464+
461465
precise_float : bool, default False
462466
Set to enable usage of higher precision (strtod) function when
463467
decoding string to double values. Default (False) is to use fast but

pandas/tests/io/json/test_pandas.py

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def assert_json_roundtrip_equal(result, expected, orient):
3939
tm.assert_frame_equal(result, expected)
4040

4141

42+
@pytest.mark.filterwarnings("ignore:the 'numpy' keyword is deprecated:FutureWarning")
4243
class TestPandasContainer:
4344
@pytest.fixture(scope="function", autouse=True)
4445
def setup(self, datapath):
@@ -1606,3 +1607,10 @@ def test_emca_262_nan_inf_support(self):
16061607
["a", np.nan, "NaN", np.inf, "Infinity", -np.inf, "-Infinity"]
16071608
)
16081609
tm.assert_frame_equal(result, expected)
1610+
1611+
def test_deprecate_numpy_argument_read_json(self):
1612+
# GH 28512
1613+
expected = DataFrame([1, 2, 3])
1614+
with tm.assert_produces_warning(FutureWarning):
1615+
result = read_json(expected.to_json(), numpy=True)
1616+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)