Skip to content

Fix 20599 overflow error when int in json is too large #21410

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion pandas/io/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@
from .table_schema import build_table_schema, parse_table_schema
from pandas.core.dtypes.common import is_period_dtype

loads = json.loads

def loads(*args, **kwargs):
try:
return json.loads(*args, **kwargs)
except ValueError as err:
# if ValueError is from too large aa value return []
if err.args[0] == 'Value is too big':
return []
else:
# in case of something like '{"key":b:a:d}' re raise
raise

dumps = json.dumps

TABLE_SCHEMA_VERSION = '0.20.0'
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,3 +1222,10 @@ def test_index_false_error_to_json(self, orient):
"valid when 'orient' is "
"'split' or 'table'"):
df.to_json(orient=orient, index=False)

@pytest.mark.parametrize('orient', [
'records', 'index', 'columns', 'values'
])
def test_int_overflow(self, orient):
bar = json.dumps({'foo': 2**100000})
read_json(bar, orient=orient)