Skip to content

BUG: Fix precision loss in read_json #59284

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

Merged
merged 17 commits into from
Sep 24, 2024
Merged
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ I/O
- 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`)
- Bug in :meth:`read_excel` raising ``ValueError`` when passing array of boolean values when ``dtype="boolean"``. (:issue:`58159`)
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
- Bug in :meth:`read_json` where extreme value integers in string format were incorrectly parsed as a different integer number (:issue:`20608`)
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ def _try_convert_data(
"""
Try to parse a Series into a column by inferring dtype.
"""
org_data = data
# don't try to coerce, unless a force conversion
if use_dtypes:
if not self.dtype:
Expand Down Expand Up @@ -1222,7 +1223,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 = org_data.astype("int64")
if (new_data == data).all():
data = new_data
converted = True
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2286,3 +2286,15 @@ 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_large_number():
# GH#20608
result = read_json(
StringIO('["9999999999999999"]'),
orient="values",
typ="series",
convert_dates=False,
)
expected = Series([9999999999999999])
tm.assert_series_equal(result, expected)
Loading