Skip to content

Commit 02b6ab4

Browse files
committed
BUG: fix broken error message in ujson.encode() (GH18878)
1 parent c4489cb commit 02b6ab4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pandas/_libs/src/ujson/python/objToJSON.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -1986,11 +1986,9 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
19861986
tc->type = JT_DOUBLE;
19871987
return;
19881988
} else if (PyArray_Check(obj) && PyArray_CheckScalar(obj)) {
1989-
tmpObj = PyObject_Repr(obj);
19901989
PyErr_Format(PyExc_TypeError,
1991-
"%s (0d array) is not JSON serializable at the moment",
1992-
PyBytes_AS_STRING(tmpObj));
1993-
Py_DECREF(tmpObj);
1990+
"%R (0d array) is not JSON serializable at the moment",
1991+
obj);
19941992
goto INVALID;
19951993
}
19961994

pandas/tests/io/json/test_ujson.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,10 @@ def test_array_float(self):
780780
tm.assert_almost_equal(arr, arr_out)
781781

782782
def test_0d_array(self):
783-
with pytest.raises(TypeError):
783+
msg = "array(1) (0d array) is not JSON serializable at the moment"
784+
with pytest.raises(TypeError) as excinfo:
784785
ujson.encode(np.array(1))
786+
assert str(excinfo.value) == msg
785787

786788
@pytest.mark.parametrize(
787789
"bad_input,exc_type,kwargs",

0 commit comments

Comments
 (0)