Skip to content
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

BUG: Remove read_json datetime deprecation warning #59743

Open
wants to merge 5 commits into
base: 2.3.x
Choose a base branch
from
Open
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 @@ -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:
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,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():
Expand Down
Loading