Skip to content

Commit ce28bb5

Browse files
committed
CLN: separate out groupby algorithms to separate lib
1 parent 32dd929 commit ce28bb5

File tree

8 files changed

+398
-365
lines changed

8 files changed

+398
-365
lines changed

pandas/_libs/algos.pxd

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from util cimport numeric
2+
from numpy cimport float64_t, double_t
3+
4+
cpdef numeric kth_smallest(numeric[:] a, Py_ssize_t k)
5+
6+
cdef inline Py_ssize_t swap(numeric *a, numeric *b) nogil except -1:
7+
cdef numeric t
8+
9+
# cython doesn't allow pointer dereference so use array syntax
10+
t = a[0]
11+
a[0] = b[0]
12+
b[0] = t
13+
return 0
14+
15+
16+
cdef inline kth_smallest_c(float64_t* a, Py_ssize_t k, Py_ssize_t n):
17+
cdef:
18+
Py_ssize_t i, j, l, m
19+
double_t x, t
20+
21+
l = 0
22+
m = n -1
23+
while (l<m):
24+
x = a[k]
25+
i = l
26+
j = m
27+
28+
while 1:
29+
while a[i] < x: i += 1
30+
while x < a[j]: j -= 1
31+
if i <= j:
32+
swap(&a[i], &a[j])
33+
i += 1; j -= 1
34+
35+
if i > j: break
36+
37+
if j < k: l = i
38+
if k < i: m = j
39+
return a[k]

0 commit comments

Comments
 (0)