8000 Fix PyArray_SearchSorted signature (GH-3606) · cython/cython@e426bbd · GitHub
[go: up one dir, main page]

Skip to content

Commit e426bbd

Browse files
jbrockmendelscoder
authored andcommitted
Fix PyArray_SearchSorted signature (GH-3606)
1 parent 5f9800a commit e426bbd

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Cython/Includes/numpy/__init__.pxd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ cdef extern from "numpy/arrayobject.h":
341341
PyObject_Free(info.strides)
342342
# info.shape was stored after info.strides in the same block
343343

344-
345344
ctypedef unsigned char npy_bool
346345

347346
ctypedef signed char npy_byte
@@ -686,7 +685,7 @@ cdef extern from "numpy/arrayobject.h":
686685
object PyArray_Choose (ndarray, object, ndarray, NPY_CLIPMODE)
687686
int PyArray_Sort (ndarray, int, NPY_SORTKIND)
688687
object PyArray_ArgSort (ndarray, int, NPY_SORTKIND)
689-
object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE)
688+
object PyArray_SearchSorted (ndarray, object, NPY_SEARCHSIDE, PyObject*)
690689
object PyArray_ArgMax (ndarray, int, ndarray)
691690
object PyArray_ArgMin (ndarray, int, ndarray)
692691
object PyArray_Reshape (ndarray, object)

tests/run/numpy_test.pyx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ cimport cython
77
import re
88
import sys
99

10+
# initialise NumPy C-API
11+
np.import_array()
12+
1013

1114
def little_endian():
1215
cdef int endian_detector = 1
@@ -182,7 +185,7 @@ try:
182185
('a', np.dtype('i,i')),\
183186
('b', np.dtype('i,i'))\
184187
])))) # doctest: +NORMALIZE_WHITESPACE
185-
array([((0, 0), (0, 0)), ((1, 2), (1, 4)), ((1, 2), (1, 4))],
188+
array([((0, 0), (0, 0)), ((1, 2), (1, 4)), ((1, 2), (1, 4))],
186189
dtype=[('a', [('f0', '!i4'), ('f1', '!i4')]), ('b', [('f0', '!i4'), ('f1', '!i4')])])
187190
188191
>>> print(test_nested_dtypes(np.zeros((3,), dtype=np.dtype([\
@@ -235,7 +238,7 @@ try:
235238
8,16
236239
237240
>>> test_point_record() # doctest: +NORMALIZE_WHITESPACE
238-
array([(0., 0.), (1., -1.), (2., -2.)],
241+
array([(0., 0.), (1., -1.), (2., -2.)],
239242
dtype=[('x', '!f8'), ('y', '!f8')])
240243
241244
"""
@@ -947,4 +950,16 @@ def test_broadcast_comparison(np.ndarray[double, ndim=1] a):
947950
return a == 0, obj == 0, a == 1, obj == 1
948951

949952

950-
include "numpy_common.pxi"
953+
@testcase
954+
def test_c_api_searchsorted(np.ndarray arr, other):
955+
"""
956+
>>> arr = np.random.randn(10)
957+
>>> other = np.random.randn(5)
958+
>>> result, expected = test_c_api_searchsorted(arr, other)
959+
>>> (result == expected).all()
960+
True
961+
"""
962+
result = np.PyArray_SearchSorted(arr, other, np.NPY_SEARCHRIGHT, NULL)
963+
964+
expected = arr.searchsorted(other, side="right")
965+
return result, expected

0 commit comments

Comments
 (0)
0