Skip to content

Commit b012cf1

Browse files
authored
simplify json get_values (#32731)
1 parent e5cd7b1 commit b012cf1

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,6 @@ static PyObject *get_values(PyObject *obj) {
237237
}
238238
}
239239

240-
if ((values == NULL) && PyObject_HasAttrString(obj, "get_block_values_for_json")) {
241-
PRINTMARK();
242-
values = PyObject_CallMethod(obj, "get_block_values_for_json", NULL);
243-
244-
if (values == NULL) {
245-
// Clear so we can subsequently try another method
246-
PyErr_Clear();
247-
} else if (!PyArray_CheckExact(values)) {
248-
// Didn't get a numpy array, so keep trying
249-
PRINTMARK();
250-
Py_DECREF(values);
251-
values = NULL;
252-
}
253-
}
254-
255240
if (values == NULL) {
256241
PyObject *typeRepr = PyObject_Repr((PyObject *)Py_TYPE(obj));
257242
PyObject *repr;
@@ -780,7 +765,7 @@ void PdBlock_iterBegin(JSOBJ _obj, JSONTypeContext *tc) {
780765
goto BLKRET;
781766
}
782767

783-
tmp = get_values(block);
768+
tmp = PyObject_CallMethod(block, "get_block_values_for_json", NULL);
784769
if (!tmp) {
785770
((JSONObjectEncoder *)tc->encoder)->errorMsg = "";
786771
Py_DECREF(block);
@@ -1266,7 +1251,7 @@ int DataFrame_iterNext(JSOBJ obj, JSONTypeContext *tc) {
12661251
} else if (index == 2) {
12671252
memcpy(GET_TC(tc)->cStr, "data", sizeof(char) * 5);
12681253
if (is_simple_frame(obj)) {
1269-
GET_TC(tc)->itemValue = get_values(obj);
1254+
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "values");
12701255
if (!GET_TC(tc)->itemValue) {
12711256
return 0;
12721257
}
@@ -1935,7 +1920,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
19351920
pc->iterNext = NpyArr_iterNext;
19361921
pc->iterGetName = NpyArr_iterGetName;
19371922

1938-
pc->newObj = get_values(obj);
1923+
pc->newObj = PyObject_GetAttrString(obj, "values");
19391924
if (!pc->newObj) {
19401925
goto INVALID;
19411926
}

0 commit comments

Comments
 (0)