Skip to content

BUG: Integer Overflow in read_json with big number in string #30329

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 6 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ I/O
- Bug in :func:`read_json` where default encoding was not set to ``utf-8`` (:issue:`29565`)
- Bug in :class:`PythonParser` where str and bytes were being mixed when dealing with the decimal field (:issue:`29650`)
- :meth:`read_gbq` now accepts ``progress_bar_type`` to display progress bar while the data downloads. (:issue:`29857`)
- Bug in :meth: `read_json` where integer overflow was occuring when json contains big number strings. (:issue:`30320`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no space before the `

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should move this to 1.1 at this point


Plotting
^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/json/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
if (new_data == data).all():
data = new_data
result = True
except (TypeError, ValueError):
except (TypeError, ValueError, OverflowError):
pass

# coerce ints to 64
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,3 +1601,16 @@ def test_json_indent_all_orients(self, orient, expected):
def test_json_negative_indent_raises(self):
with pytest.raises(ValueError, match="must be a nonnegative integer"):
pd.DataFrame().to_json(indent=-1)

@pytest.mark.parametrize(
"json,expected",
[
(
json.dumps([{"col": "31900441201190696999"}, {"col": "3190044"}]),
DataFrame({"col": [31900441201190696999.0, 3190044.0]}),
),
],
)
def test_frame_int_overflow(self, json, expected):
result = read_json(json)
tm.assert_frame_equal(result, expected)