Skip to content

Commit 2cdb97e

Browse files
authored
BUG: Fix precision loss in read_json (#59284)
1 parent 71b395f commit 2cdb97e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Diff for: doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ I/O
630630
- Bug in :meth:`read_csv` where the order of the ``na_values`` makes an inconsistency when ``na_values`` is a list non-string values. (:issue:`59303`)
631631
- Bug in :meth:`read_excel` raising ``ValueError`` when passing array of boolean values when ``dtype="boolean"``. (:issue:`58159`)
632632
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
633+
- Bug in :meth:`read_json` where extreme value integers in string format were incorrectly parsed as a different integer number (:issue:`20608`)
633634
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
634635
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
635636
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)

Diff for: 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

Diff for: 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+
# GH#20608
2293+
result = read_json(
2294+
StringIO('["9999999999999999"]'),
2295+
orient="values",
2296+
typ="series",
2297+
convert_dates=False,
2298+
)
2299+
expected = Series([9999999999999999])
2300+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)