Skip to content

REF: remove is_simple_frame from json code #54662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 6 additions & 40 deletions pandas/_libs/src/vendored/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,6 @@ static Py_ssize_t get_attr_length(PyObject *obj, char *attr) {
return ret;
}

static int is_simple_frame(PyObject *obj) {
PyObject *mgr = PyObject_GetAttrString(obj, "_mgr");
if (!mgr) {
return 0;
}
int ret;
if (PyObject_HasAttrString(mgr, "blocks")) {
ret = (get_attr_length(mgr, "blocks") <= 1);
} else {
ret = 0;
}

Py_DECREF(mgr);
return ret;
}

static npy_int64 get_long_attr(PyObject *o, const char *attr) {
// NB we are implicitly assuming that o is a Timedelta or Timestamp, or NaT
Expand Down Expand Up @@ -1140,15 +1125,8 @@ int DataFrame_iterNext(JSOBJ obj, JSONTypeContext *tc) {
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "index");
} else if (index == 2) {
memcpy(GET_TC(tc)->cStr, "data", sizeof(char) * 5);
if (is_simple_frame(obj)) {
GET_TC(tc)->itemValue = PyObject_GetAttrString(obj, "values");
if (!GET_TC(tc)->itemValue) {
return 0;
}
} else {
Py_INCREF(obj);
GET_TC(tc)->itemValue = obj;
}
Py_INCREF(obj);
GET_TC(tc)->itemValue = obj;
} else {
return 0;
}
Expand Down Expand Up @@ -1756,22 +1734,10 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
return;
}

if (is_simple_frame(obj)) {
pc->iterBegin = NpyArr_iterBegin;
pc->iterEnd = NpyArr_iterEnd;
pc->iterNext = NpyArr_iterNext;
pc->iterGetName = NpyArr_iterGetName;

pc->newObj = PyObject_GetAttrString(obj, "values");
if (!pc->newObj) {
goto INVALID;
}
} else {
pc->iterBegin = PdBlock_iterBegin;
pc->iterEnd = PdBlock_iterEnd;
pc->iterNext = PdBlock_iterNext;
pc->iterGetName = PdBlock_iterGetName;
}
pc->iterBegin = PdBlock_iterBegin;
pc->iterEnd = PdBlock_iterEnd;
pc->iterNext = PdBlock_iterNext;
pc->iterGetName = PdBlock_iterGetName;
pc->iterGetValue = NpyArr_iterGetValue;

if (enc->outputFormat == VALUES) {
Expand Down