diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index a04ba157ce0ae..2d5c0c92b0ef7 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -132,7 +132,7 @@ MultiIndex I/O ^^^ - +- Bug in :meth:`read_json` where integer overflow was occuring when json contains big number strings. (:issue:`30320`) - - diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index ae6ae70cbac72..204807b55c877 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -942,7 +942,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 diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index bb873c71e8a35..638bcaa21bdf9 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1640,3 +1640,10 @@ def test_deprecate_numpy_argument_read_json(self): with tm.assert_produces_warning(FutureWarning): result = read_json(expected.to_json(), numpy=True) tm.assert_frame_equal(result, expected) + + def test_frame_int_overflow(self): + # GH 30320 + encoded_json = json.dumps([{"col": "31900441201190696999"}, {"col": "Text"}]) + expected = DataFrame({"col": ["31900441201190696999", "Text"]}) + result = read_json(encoded_json) + tm.assert_frame_equal(result, expected)