Skip to content

Commit 091584a

Browse files
committed
BUG: Fix precision loss in read_json
Fixes pandas-dev#20608
1 parent 2419343 commit 091584a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/io/json/_json.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ def _try_convert_data(
11681168
"""
11691169
Try to parse a Series into a column by inferring dtype.
11701170
"""
1171+
org_data = data
11711172
# don't try to coerce, unless a force conversion
11721173
if use_dtypes:
11731174
if not self.dtype:
@@ -1222,7 +1223,7 @@ def _try_convert_data(
12221223
if len(data) and data.dtype in ("float", "object"):
12231224
# coerce ints if we can
12241225
try:
1225-
new_data = data.astype("int64")
1226+
new_data = org_data.astype("int64")
12261227
if (new_data == data).all():
12271228
data = new_data
12281229
converted = True

pandas/tests/io/json/test_pandas.py

+12
Original file line numberDiff line numberDiff line change
@@ -2286,3 +2286,15 @@ def test_read_json_lines_rangeindex():
22862286
result = read_json(StringIO(data), lines=True).index
22872287
expected = RangeIndex(2)
22882288
tm.assert_index_equal(result, expected, exact=True)
2289+
2290+
2291+
def test_large_number():
2292+
assert (
2293+
read_json(
2294+
StringIO('["9999999999999999"]'),
2295+
orient="values",
2296+
typ="series",
2297+
convert_dates=False,
2298+
)[0]
2299+
== 9999999999999999
2300+
)

0 commit comments

Comments
 (0)