Skip to content

Commit 32d9ad4

Browse files
committed
Clean up Decimal to utf8 convertion and switch to using PyObject_Format() to suppress scientific notation
1 parent 1c6781d commit 32d9ad4

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,25 +376,18 @@ static char *PyTimeToJSON(JSOBJ _obj, JSONTypeContext *tc, size_t *outLen) {
376376
static char *PyDecimalToUTF8Callback(JSOBJ _obj, JSONTypeContext *tc,
377377
size_t *len) {
378378
PyObject *obj = (PyObject *)_obj;
379-
PyObject *str = PyObject_Str(obj);
379+
PyObject *format_spec = PyUnicode_FromStringAndSize("f", 1);
380+
PyObject *str = PyObject_Format(obj, format_spec);
381+
Py_DECREF(format_spec);
382+
380383
if (str == NULL) {
381384
*len = 0;
382-
if (!PyErr_Occurred()) {
383-
PyErr_SetString(PyExc_ValueError, "Failed to convert decimal");
384-
}
385385
((JSONObjectEncoder *)tc->encoder)->errorMsg = "";
386386
return NULL;
387387
}
388-
if (PyUnicode_Check(str)) {
389-
PyObject *tmp = str;
390-
str = PyUnicode_AsUTF8String(str);
391-
Py_DECREF(tmp);
392-
}
393388

394389
GET_TC(tc)->newObj = str;
395-
396-
*len = PyBytes_GET_SIZE(str);
397-
char *outValue = PyBytes_AS_STRING(str);
390+
char *outValue = (char *)PyUnicode_AsUTF8AndSize(str, (Py_ssize_t *)len);
398391
return outValue;
399392
}
400393

0 commit comments

Comments
 (0)