Skip to content

Commit ee2e6de

Browse files
WillAydjreback
authored andcommitted
Fixed read_json int overflow (#18905)
1 parent edfb784 commit ee2e6de

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ I/O
318318
- Bug in :func:`read_csv` where a ``MultiIndex`` with duplicate columns was not being mangled appropriately (:issue:`18062`)
319319
- Bug in :func:`read_sas` where a file with 0 variables gave an ``AttributeError`` incorrectly. Now it gives an ``EmptyDataError`` (:issue:`18184`)
320320
- Bug in :func:`DataFrame.to_latex()` where pairs of braces meant to serve as invisible placeholders were escaped (:issue:`18667`)
321+
- Bug in :func:`read_json` where large numeric values were causing an ``OverflowError`` (:issue:`18842`)
321322
-
322323

323324
Plotting

pandas/io/json/json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def _try_convert_to_date(self, data):
724724
if new_data.dtype == 'object':
725725
try:
726726
new_data = data.astype('int64')
727-
except (TypeError, ValueError):
727+
except (TypeError, ValueError, OverflowError):
728728
pass
729729

730730
# ignore numbers that are out of range

pandas/tests/io/json/test_pandas.py

+14
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,20 @@ def test_read_jsonl_unicode_chars(self):
10741074
columns=['a', 'b'])
10751075
assert_frame_equal(result, expected)
10761076

1077+
def test_read_json_large_numbers(self):
1078+
# GH18842
1079+
json = '{"articleId": "1404366058080022500245"}'
1080+
json = StringIO(json)
1081+
result = read_json(json, typ="series")
1082+
expected = Series(1.404366e+21, index=['articleId'])
1083+
assert_series_equal(result, expected)
1084+
1085+
json = '{"0": {"articleId": "1404366058080022500245"}}'
1086+
json = StringIO(json)
1087+
result = read_json(json)
1088+
expected = DataFrame(1.404366e+21, index=['articleId'], columns=[0])
1089+
assert_frame_equal(result, expected)
1090+
10771091
def test_to_jsonl(self):
10781092
# GH9180
10791093
df = DataFrame([[1, 2], [1, 2]], columns=['a', 'b'])

0 commit comments

Comments
 (0)