Skip to content

Commit e6ea0e8

Browse files
committed
Fixed read_json int overflow
1 parent 316acbf commit e6ea0e8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/io/json/json.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 0 deletions
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)