Skip to content

Commit 47922d3

Browse files
rohitkg98WillAyd
authored andcommitted
BUG: Integer Overflow in read_json with big number in string (#30329)
1 parent 4da554f commit 47922d3

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ MultiIndex
191191

192192
I/O
193193
^^^
194-
194+
- Bug in :meth:`read_json` where integer overflow was occuring when json contains big number strings. (:issue:`30320`)
195195
-
196196
-
197197

pandas/io/json/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ def _try_convert_data(self, name, data, use_dtypes=True, convert_dates=True):
942942
if (new_data == data).all():
943943
data = new_data
944944
result = True
945-
except (TypeError, ValueError):
945+
except (TypeError, ValueError, OverflowError):
946946
pass
947947

948948
# coerce ints to 64

pandas/tests/io/json/test_pandas.py

+7
Original file line numberDiff line numberDiff line change
@@ -1640,3 +1640,10 @@ def test_deprecate_numpy_argument_read_json(self):
16401640
with tm.assert_produces_warning(FutureWarning):
16411641
result = read_json(expected.to_json(), numpy=True)
16421642
tm.assert_frame_equal(result, expected)
1643+
1644+
def test_frame_int_overflow(self):
1645+
# GH 30320
1646+
encoded_json = json.dumps([{"col": "31900441201190696999"}, {"col": "Text"}])
1647+
expected = DataFrame({"col": ["31900441201190696999", "Text"]})
1648+
result = read_json(encoded_json)
1649+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)