Skip to content

Commit 0b554ad

Browse files
mattipjreback
authored andcommitted
COMPAT: PyPy can only call PyList_GET_SIZE on a PyListObject
BUG: bring implementation into compliance with cython documentation BUG: fix improper use of conditional compilation closes pandas-dev#15080
1 parent 42cdb34 commit 0b554ad

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pandas/lib.pyx

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ from cpython cimport (PyDict_New, PyDict_GetItem, PyDict_SetItem,
2626
PyBytes_GET_SIZE,
2727
PyUnicode_GET_SIZE)
2828

29-
try:
30-
from cpython cimport PyString_GET_SIZE
31-
except ImportError:
29+
cdef extern from "Python.h":
30+
int PY_MAJOR_VERSION
31+
32+
if PY_MAJOR_VERSION >= 3:
3233
from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE
34+
else:
35+
from cpython cimport PyString_GET_SIZE
3336

3437
cdef extern from "Python.h":
3538
Py_ssize_t PY_SSIZE_T_MAX

pandas/src/hashtable_class_helper.pxi.in

+5-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,11 @@ cdef class PyObjectHashTable(HashTable):
691691

692692
def __dealloc__(self):
693693
if self.table is not NULL:
694-
self.destroy()
694+
# cython documentation -
695+
# "don’t call any other methods of the object"
696+
# self.destroy()
697+
kh_destroy_pymap(self.table)
698+
self.table = NULL
695699

696700
def __len__(self):
697701
return self.table.size

pandas/src/ujson/python/JSONtoObj.c

+4
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ int Object_npyObjectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) {
427427

428428
// only fill label array once, assumes all column labels are the same
429429
// for 2-dimensional arrays.
430+
#ifdef PYPY_VERSION
431+
if (PyObject_GET_SIZE(npyarr->labels[labelidx]) <= npyarr->elcount) {
432+
#else
430433
if (PyList_GET_SIZE(npyarr->labels[labelidx]) <= npyarr->elcount) {
434+
#endif
431435
PyList_Append(npyarr->labels[labelidx], label);
432436
}
433437

0 commit comments

Comments
 (0)