Skip to content

Commit 76e05a1

Browse files
committed
MAINT,BUG: Fix mtrand for Cython 0.27.
The `import_array()` macro, that defined a C code block that included a return, was not handled correctly. The fix here is to cdef a replacement `import_array` function with a defined error return. The new function is a slight variation of the corresponding function defined by Cython.
1 parent 41093de commit 76e05a1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

numpy/random/mtrand/numpy.pxd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# :Author: Travis Oliphant
2+
from cpython.exc cimport PyErr_Print
23

34
cdef extern from "numpy/npy_no_deprecated_api.h": pass
45

@@ -133,7 +134,7 @@ cdef extern from "numpy/arrayobject.h":
133134

134135
dtype PyArray_DescrFromType(int)
135136

136-
void import_array()
137+
int _import_array() except -1
137138

138139
# include functions that were once macros in the new api
139140

@@ -150,3 +151,12 @@ cdef extern from "numpy/arrayobject.h":
150151
int PyArray_TYPE(ndarray arr)
151152
int PyArray_CHKFLAGS(ndarray arr, int flags)
152153
object PyArray_GETITEM(ndarray arr, char *itemptr)
154+
155+
156+
# copied from cython version with addition of PyErr_Print.
157+
cdef inline int import_array() except -1:
158+
try:
159+
_import_array()
160+
except Exception:
161+
PyErr_Print()
162+
raise ImportError("numpy.core.multiarray failed to import")

tools/travis-before-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626
source venv/bin/activate
2727
python -V
2828
pip install --upgrade pip setuptools
29-
pip install nose pytz cython==0.26
29+
pip install nose pytz cython
3030
if [ -n "$USE_ASV" ]; then pip install asv; fi
3131
popd

0 commit comments

Comments
 (0)