Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d54da80

Browse files
committed
TST: Check that Cython intp conversion uses normal integer rules
1 parent eb1302d commit d54da80

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ def get_default_integer():
128128
if cnp.NPY_DEFAULT_INT == cnp.NPY_INTP:
129129
return cnp.dtype("intp")
130130
return None
131+
132+
def conv_intp(cnp.intp_t val):
133+
return val

numpy/_core/tests/test_cython.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,15 @@ def test_multiiter_fields(install_temp, arrays):
192192
for x, y in zip(bcast.iters, checks.get_multiiter_iters(bcast))
193193
]
194194
)
195+
196+
197+
def test_conv_intp(install_temp):
198+
import checks
199+
200+
class myint:
201+
def __int__(self):
202+
return 3
203+
204+
# These conversion passes via `__int__`, not `__index__`:
205+
assert checks.conv_intp(3.) == 3
206+
assert checks.conv_intp(myint()) == 3

0 commit comments

Comments
 (0)