From cf458cf81aa0f16d97e5b8684665f1550fbfb6dc Mon Sep 17 00:00:00 2001 From: mattip Date: Sat, 7 Jan 2017 21:02:05 +0200 Subject: [PATCH 1/4] COMPAT: PyPy can only call PyList_GET_SIZE on a PyListObject --- pandas/src/ujson/python/JSONtoObj.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/src/ujson/python/JSONtoObj.c b/pandas/src/ujson/python/JSONtoObj.c index b0132532c16af..6be4584b854f5 100644 --- a/pandas/src/ujson/python/JSONtoObj.c +++ b/pandas/src/ujson/python/JSONtoObj.c @@ -427,7 +427,11 @@ int Object_npyObjectAddKey(void *prv, JSOBJ obj, JSOBJ name, JSOBJ value) { // only fill label array once, assumes all column labels are the same // for 2-dimensional arrays. +#ifdef PYPY_VERSION + if (PyObject_GET_SIZE(npyarr->labels[labelidx]) <= npyarr->elcount) { +#else if (PyList_GET_SIZE(npyarr->labels[labelidx]) <= npyarr->elcount) { +#endif PyList_Append(npyarr->labels[labelidx], label); } From df4cffd731b97fc8fe3d6480ca1f1350ab7ff2c8 Mon Sep 17 00:00:00 2001 From: mattip Date: Sat, 7 Jan 2017 21:20:11 +0200 Subject: [PATCH 2/4] BUG: bring implementation into compliance with cython documentation --- pandas/src/hashtable_class_helper.pxi.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/src/hashtable_class_helper.pxi.in b/pandas/src/hashtable_class_helper.pxi.in index b26839599ef38..6bf94c9366c8a 100644 --- a/pandas/src/hashtable_class_helper.pxi.in +++ b/pandas/src/hashtable_class_helper.pxi.in @@ -691,7 +691,11 @@ cdef class PyObjectHashTable(HashTable): def __dealloc__(self): if self.table is not NULL: - self.destroy() + # cython documentation - + # "don’t call any other methods of the object" + # self.destroy() + kh_destroy_pymap(self.table) + self.table = NULL def __len__(self): return self.table.size From 91522c61e38254280450702ede52f551340fdd9f Mon Sep 17 00:00:00 2001 From: mattip Date: Sun, 8 Jan 2017 20:07:18 +0200 Subject: [PATCH 3/4] BUG: fix improper use of conditional compilation --- pandas/lib.pyx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/lib.pyx b/pandas/lib.pyx index 761969491cfc7..131ac1fc78959 100644 --- a/pandas/lib.pyx +++ b/pandas/lib.pyx @@ -26,10 +26,13 @@ from cpython cimport (PyDict_New, PyDict_GetItem, PyDict_SetItem, PyBytes_GET_SIZE, PyUnicode_GET_SIZE) -try: - from cpython cimport PyString_GET_SIZE -except ImportError: +cdef extern from "Python.h": + int PY_MAJOR_VERSION + +if PY_MAJOR_VERSION >= 3: from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE +else: + from cpython cimport PyString_GET_SIZE cdef extern from "Python.h": Py_ssize_t PY_SSIZE_T_MAX From b38d7bee3c7fe25972dc9d3e9620fc95ac0e615b Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 10 Jan 2017 18:51:42 +0200 Subject: [PATCH 4/4] BUG: fix improper use of conditional compilation, add env var --- pandas/lib.pyx | 9 +++------ setup.py | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/lib.pyx b/pandas/lib.pyx index 131ac1fc78959..e3ee468e1a23b 100644 --- a/pandas/lib.pyx +++ b/pandas/lib.pyx @@ -26,13 +26,10 @@ from cpython cimport (PyDict_New, PyDict_GetItem, PyDict_SetItem, PyBytes_GET_SIZE, PyUnicode_GET_SIZE) -cdef extern from "Python.h": - int PY_MAJOR_VERSION - -if PY_MAJOR_VERSION >= 3: - from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE -else: +IF PY_MAJOR_VERSION == 2: from cpython cimport PyString_GET_SIZE +ELSE: + from cpython cimport PyUnicode_GET_SIZE as PyString_GET_SIZE cdef extern from "Python.h": Py_ssize_t PY_SSIZE_T_MAX diff --git a/setup.py b/setup.py index 0a84cf527bfb1..015db43afada0 100755 --- a/setup.py +++ b/setup.py @@ -150,6 +150,12 @@ def build_extensions(self): with open(outfile, "w") as f: f.write(pyxcontent) + # used in lib.pyx, assumes old_build_ext + if not self.cython_compile_time_env: + self.cython_compile_time_env = {} + major = sys.version_info.major + self.cython_compile_time_env['PY_MAJOR_VERSION'] = major + numpy_incl = pkg_resources.resource_filename('numpy', 'core/include') for ext in self.extensions: