Skip to content

Commit

Permalink
Clean up Decimal to utf8 convertion and switch to using PyObject_Form…
Browse files Browse the repository at this point in the history
…at() to suppress scientific notation
  • Loading branch information
Tolker-KU committed Jan 13, 2025
1 parent 1c6781d commit 32d9ad4
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pandas/_libs/src/vendored/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,18 @@ static char *PyTimeToJSON(JSOBJ _obj, JSONTypeContext *tc, size_t *outLen) {
static char *PyDecimalToUTF8Callback(JSOBJ _obj, JSONTypeContext *tc,
size_t *len) {
PyObject *obj = (PyObject *)_obj;
PyObject *str = PyObject_Str(obj);
PyObject *format_spec = PyUnicode_FromStringAndSize("f", 1);
PyObject *str = PyObject_Format(obj, format_spec);
Py_DECREF(format_spec);

if (str == NULL) {
*len = 0;
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError, "Failed to convert decimal");
}
((JSONObjectEncoder *)tc->encoder)->errorMsg = "";
return NULL;
}
if (PyUnicode_Check(str)) {
PyObject *tmp = str;
str = PyUnicode_AsUTF8String(str);
Py_DECREF(tmp);
}

GET_TC(tc)->newObj = str;

*len = PyBytes_GET_SIZE(str);
char *outValue = PyBytes_AS_STRING(str);
char *outValue = (char *)PyUnicode_AsUTF8AndSize(str, (Py_ssize_t *)len);
return outValue;
}

Expand Down

0 comments on commit 32d9ad4

Please sign in to comment.