From 1c6b7868f65042cdfe5cbc36b4021030772fc959 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Fri, 3 Jan 2020 01:30:20 +0000 Subject: [PATCH 1/7] Merge master Co-authored-by: Luca Ionescu --- doc/source/whatsnew/v1.0.0.rst | 1 + pandas/io/json/_json.py | 4 ++++ pandas/tests/io/json/test_pandas.py | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 788cb3db51d8a..09058efc386a6 100755 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -545,6 +545,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`). - :meth:`DataFrame.to_stata`, :meth:`DataFrame.to_feather`, and :meth:`DataFrame.to_parquet` argument "fname" is deprecated, use "path" instead (:issue:`23574`) - The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index f5008f0c311ad..d85d75453dbde 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -11,6 +11,7 @@ from pandas._libs.tslibs import iNaT from pandas._typing import JSONSerializable from pandas.errors import AbstractMethodError +from pandas.util._decorators import deprecate_kwarg from pandas.core.dtypes.common import ensure_str, is_period_dtype @@ -346,6 +347,7 @@ def _write( return serialized +@deprecate_kwarg(old_arg_name="numpy", new_arg_name=None) def read_json( path_or_buf=None, orient=None, @@ -459,6 +461,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 532d5215be902..aec66b9f06518 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 @@ -1606,3 +1607,13 @@ def test_emca_262_nan_inf_support(self): ["a", np.nan, "NaN", np.inf, "Infinity", -np.inf, "-Infinity"] ) tm.assert_frame_equal(result, expected) + + @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) From 42a46d79ccc2fff2f38428fb8eee9309ddecaeb2 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 4 Jan 2020 16:46:26 +0000 Subject: [PATCH 2/7] Fix test failures ignore FutureWarning --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 96af78c77feb8..5bab4ae8e4806 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,6 +66,7 @@ xfail_strict = True filterwarnings = error:Sparse:FutureWarning error:The SparseArray:FutureWarning + ignore: the 'numpy' keyword is deprecated:FutureWarning [coverage:run] branch = False From 8331d065c270308893d2ca79c71d47b659f2d400 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 4 Jan 2020 16:47:12 +0000 Subject: [PATCH 3/7] Filter warning correctly --- pandas/tests/io/json/test_pandas.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index aec66b9f06518..72f00df2e7b55 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1608,12 +1608,10 @@ def test_emca_262_nan_inf_support(self): ) tm.assert_frame_equal(result, expected) - @pytest.mark.filterwarnings("ignore:.*msgpack:FutureWarning") + @pytest.mark.filterwarnings("ignore:the 'numpy' keyword:FutureWarning") def test_deprecate_numpy_argument_read_json(self): - # https://github.com/pandas-dev/pandas/issues/28512 + # GH 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) + with tm.assert_produces_warning(FutureWarning): + result = read_json(expected.to_json(), numpy=True) + tm.assert_frame_equal(result, expected) From 3ba4169d370a6a152b6d4f7a3ac0fa1d00609a86 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 4 Jan 2020 17:18:39 +0000 Subject: [PATCH 4/7] Fix imports --- pandas/tests/io/json/test_pandas.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 72f00df2e7b55..00394e626b408 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -3,7 +3,6 @@ from io import StringIO import json import os -from warnings import catch_warnings, filterwarnings import numpy as np import pytest From 5068771a1c68bc6bb862422906620415fc05a234 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 4 Jan 2020 19:10:45 +0000 Subject: [PATCH 5/7] Add warning annotation --- pandas/tests/io/json/test_pandas.py | 1 + setup.cfg | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 8e8e361dea891..6076ee3c13d9f 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -39,6 +39,7 @@ def assert_json_roundtrip_equal(result, expected, orient): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:the 'numpy' keyword is deprecated:FutureWarning") class TestPandasContainer: @pytest.fixture(scope="function", autouse=True) def setup(self, datapath): diff --git a/setup.cfg b/setup.cfg index 5b93864ed92e8..f813d1296b047 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,7 +66,6 @@ xfail_strict = True filterwarnings = error:Sparse:FutureWarning error:The SparseArray:FutureWarning - ignore: the 'numpy' keyword is deprecated:FutureWarning [coverage:run] branch = False From 8d65aa7e163f6dddebab2ef021a491ae0b3b8d24 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sat, 4 Jan 2020 19:12:32 +0000 Subject: [PATCH 6/7] Remove unrequired annotation --- pandas/tests/io/json/test_pandas.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 6076ee3c13d9f..e909a4952948c 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1608,7 +1608,6 @@ def test_emca_262_nan_inf_support(self): ) tm.assert_frame_equal(result, expected) - @pytest.mark.filterwarnings("ignore:the 'numpy' keyword:FutureWarning") def test_deprecate_numpy_argument_read_json(self): # GH 28512 expected = DataFrame([1, 2, 3]) From cb74fe351d0881cea36033551ccace4826b764f5 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Sun, 5 Jan 2020 01:11:15 +0000 Subject: [PATCH 7/7] Update docs --- doc/source/user_guide/io.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 82e01b62efbb9..9f99f36b6007d 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2066,6 +2066,8 @@ The Numpy parameter +++++++++++++++++++ .. note:: + This param has been deprecated as of version 1.0.0 and will raise a ``FutureWarning``. + This supports numeric data only. Index and columns labels may be non-numeric, e.g. strings, dates etc. If ``numpy=True`` is passed to ``read_json`` an attempt will be made to sniff @@ -2088,6 +2090,7 @@ data: %timeit pd.read_json(jsonfloats) .. ipython:: python + :okwarning: %timeit pd.read_json(jsonfloats, numpy=True) @@ -2102,6 +2105,7 @@ The speedup is less noticeable for smaller datasets: %timeit pd.read_json(jsonfloats) .. ipython:: python + :okwarning: %timeit pd.read_json(jsonfloats, numpy=True)