From c3ea7e5d16d604a90131a0749758a8e459e570fd Mon Sep 17 00:00:00 2001 From: ssikdar1 Date: Sun, 10 Jun 2018 11:15:41 -0400 Subject: [PATCH 1/2] Python int too large error (20599) --- pandas/io/json/json.py | 12 +++++++++++- pandas/tests/io/json/test_pandas.py | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pandas/io/json/json.py b/pandas/io/json/json.py index 1627b2f4d3ec3..c76e4c5529181 100644 --- a/pandas/io/json/json.py +++ b/pandas/io/json/json.py @@ -19,7 +19,17 @@ 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' diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 7e497c395266f..a57c286e1d0fb 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1222,3 +1222,11 @@ 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) + From c5ec468ad6803ee736b39ec70587fba7505f3715 Mon Sep 17 00:00:00 2001 From: ssikdar1 Date: Sun, 10 Jun 2018 11:20:46 -0400 Subject: [PATCH 2/2] Fix Pep8 issues --- pandas/io/json/json.py | 1 + pandas/tests/io/json/test_pandas.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/json/json.py b/pandas/io/json/json.py index c76e4c5529181..17492f5d5cac9 100644 --- a/pandas/io/json/json.py +++ b/pandas/io/json/json.py @@ -19,6 +19,7 @@ from .table_schema import build_table_schema, parse_table_schema from pandas.core.dtypes.common import is_period_dtype + def loads(*args, **kwargs): try: return json.loads(*args, **kwargs) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index a57c286e1d0fb..0e72e5d3abd84 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1227,6 +1227,5 @@ def test_index_false_error_to_json(self, orient): 'records', 'index', 'columns', 'values' ]) def test_int_overflow(self, orient): - bar = json.dumps({ 'foo' : 2**100000}) + bar = json.dumps({'foo': 2**100000}) read_json(bar, orient=orient) -