8000 Merge pull request #25095 from seberg/backport-cy-fix · numpy/numpy@86c2863 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86c2863

Browse files
authored
Merge pull request #25095 from seberg/backport-cy-fix
BUG: Avoid intp conversion regression in Cython 3 (backport)
2 parents 55d3f26 + 09eb7d5 commit 86c2863

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

numpy/__init__.cython-30.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cdef extern from *:
2121

2222

2323
cdef extern from "Python.h":
24-
ctypedef Py_ssize_t Py_intptr_t
24+
ctypedef int Py_intptr_t
2525

2626
cdef extern from "numpy/arrayobject.h":
2727
ctypedef Py_intptr_t npy_intp

numpy/core/tests/examples/cython/checks.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ def get_dt64_unit(obj):
3030

3131
def is_integer(obj):
3232
return isinstance(obj, (cnp.integer, int))
33+
34+
def conv_intp(cnp.intp_t val):
35+
return val

numpy/core/tests/test_cython.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,14 @@ def test_abstract_scalars(install_temp):
122122
assert checks.is_integer(1)
123123
assert checks.is_integer(np.int8(1))
124124
assert checks.is_integer(np.uint64(1))
125+
126+
def test_conv_intp(install_temp):
127+
import checks
128+
129+
class myint:
130+
def __int__(self):
131+
return 3
132+
133+
# These conversion passes via `__int__`, not `__index__`:
134+
assert checks.conv_intp(3.) == 3
135+
assert checks.conv_intp(myint()) == 3

0 commit comments

Comments
 (0)
0