1
1
# -*- coding: utf-8 -*-
2
2
3
- cimport cython
4
- from cython cimport Py_ssize_t
3
+ import cython
4
+ from cython import Py_ssize_t
5
5
6
6
from libc.stdlib cimport malloc, free
7
7
8
8
import numpy as np
9
9
cimport numpy as cnp
10
10
from numpy cimport (ndarray,
11
- double_t,
12
11
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
13
12
uint32_t, uint64_t, float32_t, float64_t)
14
13
cnp.import_array()
@@ -20,10 +19,9 @@ from algos cimport (swap, TiebreakEnumType, TIEBREAK_AVERAGE, TIEBREAK_MIN,
20
19
TIEBREAK_MAX, TIEBREAK_FIRST, TIEBREAK_DENSE)
21
20
from algos import take_2d_axis1_float64_float64, groupsort_indexer, tiebreakers
22
21
23
- cdef int64_t iNaT = get_nat()
22
+ cdef int64_t NPY_NAT = get_nat()
24
23
25
- cdef double NaN = < double > np.NaN
26
- cdef double nan = NaN
24
+ cdef float64_t NaN = < float64_t> np.NaN
27
25
28
26
29
27
cdef inline float64_t median_linear(float64_t* a, int n) nogil:
@@ -67,13 +65,13 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil:
67
65
return result
68
66
69
67
70
- # TODO: Is this redundant with algos.kth_smallest?
68
+ # TODO: Is this redundant with algos.kth_smallest
71
69
cdef inline float64_t kth_smallest_c(float64_t* a,
72
70
Py_ssize_t k,
73
71
Py_ssize_t n) nogil:
74
72
cdef:
75
73
Py_ssize_t i, j, l, m
76
- double_t x, t
74
+ float64_t x, t
77
75
78
76
l = 0
79
77
m = n - 1
@@ -109,7 +107,7 @@ def group_median_float64(ndarray[float64_t, ndim=2] out,
109
107
cdef:
110
108
Py_ssize_t i, j, N, K, ngroups, size
111
109
ndarray[int64_t] _counts
112
- ndarray data
110
+ ndarray[float64_t, ndim = 2 ] data
113
111
float64_t* ptr
114
112
115
113
assert min_count == - 1 , " 'min_count' only used in add and prod"
@@ -139,8 +137,8 @@ def group_median_float64(ndarray[float64_t, ndim=2] out,
139
137
@ cython.boundscheck (False )
140
138
@ cython.wraparound (False )
141
139
def group_cumprod_float64 (float64_t[:, :] out ,
142
- float64_t[:, :] values ,
143
- int64_t[:] labels ,
140
+ const float64_t[:, :] values ,
141
+ const int64_t[:] labels ,
144
142
bint is_datetimelike ,
145
143
bint skipna = True ):
146
144
"""
@@ -177,7 +175,7 @@ def group_cumprod_float64(float64_t[:, :] out,
177
175
@ cython.wraparound (False )
178
176
def group_cumsum (numeric[:, :] out ,
179
177
numeric[:, :] values ,
180
- int64_t[:] labels ,
178
+ const int64_t[:] labels ,
181
179
is_datetimelike ,
182
180
bint skipna = True ):
183
181
"""
@@ -217,7 +215,7 @@ def group_cumsum(numeric[:, :] out,
217
215
218
216
@ cython.boundscheck (False )
219
217
@ cython.wraparound (False )
220
- def group_shift_indexer (ndarray[ int64_t] out , ndarray[ int64_t] labels ,
218
+ def group_shift_indexer (int64_t[: ] out , const int64_t[: ] labels ,
221
219
int ngroups , int periods ):
222
220
cdef:
223
221
Py_ssize_t N, i, j, ii
@@ -291,7 +289,7 @@ def group_fillna_indexer(ndarray[int64_t] out, ndarray[int64_t] labels,
291
289
"""
292
290
cdef:
293
291
Py_ssize_t i, N
294
- ndarray[ int64_t] sorted_labels
292
+ int64_t[: ] sorted_labels
295
293
int64_t idx, curr_fill_idx= - 1 , filled_vals= 0
296
294
297
295
N = len (out)
@@ -327,10 +325,10 @@ def group_fillna_indexer(ndarray[int64_t] out, ndarray[int64_t] labels,
327
325
328
326
@ cython.boundscheck (False )
329
327
@ cython.wraparound (False )
330
- def group_any_all (ndarray[ uint8_t] out ,
331
- ndarray[ int64_t] labels ,
332
- ndarray[ uint8_t] values ,
333
- ndarray[ uint8_t] mask ,
328
+ def group_any_all (uint8_t[: ] out ,
329
+ const int64_t[: ] labels ,
330
+ const uint8_t[: ] values ,
331
+ const uint8_t[: ] mask ,
334
332
object val_test ,
335
333
bint skipna ):
336
334
""" Aggregated boolean values to show truthfulness of group elements
0 commit comments