Skip to content

Commit 1dab473

Browse files
authored
BUG: to_json failing on PyPy (#40525)
1 parent 23c9661 commit 1dab473

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

doc/source/whatsnew/v1.2.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed regressions
1616
~~~~~~~~~~~~~~~~~
1717

1818
- Fixed regression in :meth:`DataFrame.sum` when ``min_count`` greater than the :class:`DataFrame` shape was passed resulted in a ``ValueError`` (:issue:`39738`)
19+
- Fixed regression in :meth:`DataFrame.to_json` raising ``AttributeError`` when run on PyPy (:issue:`39837`)
1920
-
2021

2122
.. ---------------------------------------------------------------------------

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,6 @@ static PyObject *get_sub_attr(PyObject *obj, char *attr, char *subAttr) {
272272
return ret;
273273
}
274274

275-
static int is_simple_frame(PyObject *obj) {
276-
PyObject *check = get_sub_attr(obj, "_mgr", "is_mixed_type");
277-
int ret = (check == Py_False);
278-
279-
if (!check) {
280-
return 0;
281-
}
282-
283-
Py_DECREF(check);
284-
return ret;
285-
}
286-
287275
static Py_ssize_t get_attr_length(PyObject *obj, char *attr) {
288276
PyObject *tmp = PyObject_GetAttrString(obj, attr);
289277
Py_ssize_t ret;
@@ -301,6 +289,17 @@ static Py_ssize_t get_attr_length(PyObject *obj, char *attr) {
301289
return ret;
302290
}
303291

292+
static int is_simple_frame(PyObject *obj) {
293+
PyObject *mgr = PyObject_GetAttrString(obj, "_mgr");
294+
if (!mgr) {
295+
return 0;
296+
}
297+
int ret = (get_attr_length(mgr, "blocks") <= 1);
298+
299+
Py_DECREF(mgr);
300+
return ret;
301+
}
302+
304303
static npy_int64 get_long_attr(PyObject *o, const char *attr) {
305304
npy_int64 long_val;
306305
PyObject *value = PyObject_GetAttrString(o, attr);

0 commit comments

Comments
 (0)