Skip to content

Commit

Permalink
BUG: DataFrame.to_json OverflowError with np.long* dtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
gupta-paras committed Oct 12, 2023
1 parent b284101 commit b972f99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ I/O
- Bug in :func:`read_csv` with ``engine="pyarrow"`` where ``usecols`` wasn't working with a csv with no headers (:issue:`54459`)
- Bug in :func:`read_excel`, with ``engine="xlrd"`` (``xls`` files) erroring when file contains NaNs/Infs (:issue:`54564`)
- Bug in :func:`to_excel`, with ``OdsWriter`` (``ods`` files) writing boolean/string value (:issue:`54994`)
- Bug in :meth:`DataFrame.to_json` OverflowError with np.long* dtypes (:issue:`55403`)
- Bug in :meth:`pandas.read_excel` with an ODS file without cached formatted cell for float values (:issue:`55219`)

Period
Expand Down
5 changes: 5 additions & 0 deletions pandas/_libs/src/vendored/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,11 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
PyArray_DescrFromType(NPY_DOUBLE));
tc->type = JT_DOUBLE;
return;
} else if (PyArray_IsScalar(obj, LongDouble)) {
PyErr_Format(PyExc_TypeError,
"%R (np.longdouble) is not JSON serializable at the moment",
obj);
goto INVALID;
} else if (PyArray_Check(obj) && PyArray_CheckScalar(obj)) {
PyErr_Format(PyExc_TypeError,
"%R (0d array) is not JSON serializable at the moment",
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ def test_0d_array(self):
with pytest.raises(TypeError, match=msg):
ujson.ujson_dumps(np.array(1))

def test_array_long_double(self):
msg = re.escape("1.0 (np.longdouble) is not JSON serializable at the moment")
with pytest.raises(TypeError, match=msg):
ujson.ujson_dumps(np.longdouble(1))


class TestPandasJSONTests:
def test_dataframe(self, orient):
Expand Down

0 comments on commit b972f99

Please sign in to comment.