Skip to content

BUG: Supress read_json Spurious to_datetime FutureWarning #60313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,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:
Expand Down Expand Up @@ -1346,6 +1346,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
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2186,3 +2186,9 @@ def test_read_json_lines_rangeindex():
result = read_json(StringIO(data), lines=True).index
expected = RangeIndex(2)
tm.assert_index_equal(result, expected, exact=True)


def test_read_json_to_datetime_futurewarning_supress():
data = '{"A":{"0":"X","Y":"Y"}}'
with tm.assert_produces_warning(None):
read_json(StringIO(data))
Loading