From a55c46495141237b39b2e8003a2def7d7a56a717 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Sat, 7 Sep 2024 11:33:46 +0800 Subject: [PATCH 1/3] change convert_dates from True to self.convert_dates --- pandas/io/json/_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 9414f45215029..1806d421c6fc5 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -1210,7 +1210,7 @@ def _convert_axes(self) -> None: name=axis_name, data=ser, use_dtypes=False, - convert_dates=True, + convert_dates=self.convert_dates, is_axis=True, ) if result: From 47723f21c1317813ef819c57f0202b15b74ccea7 Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Sat, 7 Sep 2024 11:33:56 +0800 Subject: [PATCH 2/3] ignore the specific spurious warning --- pandas/io/json/_json.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 1806d421c6fc5..a1be85071ccfa 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -1357,6 +1357,12 @@ def _try_convert_to_date(self, data: Series) -> tuple[Series, bool]: "zones will raise an error", category=FutureWarning, ) + warnings.filterwarnings( + "ignore", + "The behavior of 'to_datetime' with 'unit' " + "when parsing strings is deprecated.", + category=FutureWarning, + ) new_data = to_datetime(new_data, errors="raise", unit=date_unit) except (ValueError, OverflowError, TypeError): continue From da98c4569859474de2de83eec4adefaae94cc6ae Mon Sep 17 00:00:00 2001 From: KevsterAmp Date: Sat, 7 Sep 2024 11:35:03 +0800 Subject: [PATCH 3/3] create test for read_json datetime deprecation ignore --- pandas/tests/io/json/test_pandas.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 5279f3f1cdfbe..f1082c7f1a542 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -2174,6 +2174,15 @@ def test_json_pos_args_deprecation(): buf = BytesIO() df.to_json(buf, "split") +def test_json_datetetime_deprecation_ignore(): + with pytest.warns(None) as record: + df = pd.read_json( + StringIO('{"A":{"0":"X","Y":"Y"}}'), + typ='frame', + orient='records' + ) + assert len(record) == 0 + @td.skip_if_no("pyarrow") def test_to_json_ea_null():