Skip to content

Commit

Permalink
BUG: to_json failing on PyPy (#40525)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzeitlin11 authored Mar 23, 2021
1 parent 23c9661 commit 1dab473
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed regressions
~~~~~~~~~~~~~~~~~

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

.. ---------------------------------------------------------------------------
Expand Down
23 changes: 11 additions & 12 deletions pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,6 @@ static PyObject *get_sub_attr(PyObject *obj, char *attr, char *subAttr) {
return ret;
}

static int is_simple_frame(PyObject *obj) {
PyObject *check = get_sub_attr(obj, "_mgr", "is_mixed_type");
int ret = (check == Py_False);

if (!check) {
return 0;
}

Py_DECREF(check);
return ret;
}

static Py_ssize_t get_attr_length(PyObject *obj, char *attr) {
PyObject *tmp = PyObject_GetAttrString(obj, attr);
Py_ssize_t ret;
Expand All @@ -301,6 +289,17 @@ 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 = (get_attr_length(mgr, "blocks") <= 1);

Py_DECREF(mgr);
return ret;
}

static npy_int64 get_long_attr(PyObject *o, const char *attr) {
npy_int64 long_val;
PyObject *value = PyObject_GetAttrString(o, attr);
Expand Down

0 comments on commit 1dab473

Please sign in to comment.