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: Fix precision loss in read_json #59284

Merged
merged 17 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ def _try_convert_data(
"""
Try to parse a Series into a column by inferring dtype.
"""
backup_data = data
# don't try to coerce, unless a force conversion
if use_dtypes:
if not self.dtype:
Expand Down Expand Up @@ -1221,7 +1222,7 @@ def _try_convert_data(
if len(data) and data.dtype in ("float", "object"):
# coerce ints if we can
try:
new_data = data.astype("int64")
new_data = backup_data.astype("int64")
fawazahmed0 marked this conversation as resolved.
Show resolved Hide resolved
if (new_data == data).all():
data = new_data
converted = True
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/io/json/test_large_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from io import StringIO
import pytest
import pandas as pd

def test_large_number():
fawazahmed0 marked this conversation as resolved.
Show resolved Hide resolved
assert pd.read_json(StringIO('["9999999999999999"]'),orient="values",typ="series",convert_dates=False)[0] == 9999999999999999
Loading