Skip to content

Commit 1a64333

Browse files
committed
Use memory views in .pxi.in files
1 parent 4fc75bd commit 1a64333

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

pandas/_libs/groupby_helper.pxi.in

+46-46
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def get_dispatch(dtypes):
2929

3030
@cython.wraparound(False)
3131
@cython.boundscheck(False)
32-
def group_add_{{name}}(ndarray[{{c_type}}, ndim=2] out,
33-
ndarray[int64_t] counts,
34-
ndarray[{{c_type}}, ndim=2] values,
35-
ndarray[int64_t] labels,
32+
def group_add_{{name}}({{c_type}}[:, :] out,
33+
int64_t[:] counts,
34+
{{c_type}}[:, :] values,
35+
const int64_t[:] labels,
3636
Py_ssize_t min_count=0):
3737
"""
3838
Only aggregates on axis=0
@@ -76,10 +76,10 @@ def group_add_{{name}}(ndarray[{{c_type}}, ndim=2] out,
7676

7777
@cython.wraparound(False)
7878
@cython.boundscheck(False)
79-
def group_prod_{{name}}(ndarray[{{c_type}}, ndim=2] out,
80-
ndarray[int64_t] counts,
81-
ndarray[{{c_type}}, ndim=2] values,
82-
ndarray[int64_t] labels,
79+
def group_prod_{{name}}({{c_type}}[:, :] out,
80+
int64_t[:] counts,
81+
{{c_type}}[:, :] values,
82+
const int64_t[:] labels,
8383
Py_ssize_t min_count=0):
8484
"""
8585
Only aggregates on axis=0
@@ -123,10 +123,10 @@ def group_prod_{{name}}(ndarray[{{c_type}}, ndim=2] out,
123123
@cython.wraparound(False)
124124
@cython.boundscheck(False)
125125
@cython.cdivision(True)
126-
def group_var_{{name}}(ndarray[{{c_type}}, ndim=2] out,
127-
ndarray[int64_t] counts,
128-
ndarray[{{c_type}}, ndim=2] values,
129-
ndarray[int64_t] labels,
126+
def group_var_{{name}}({{c_type}}[:, :] out,
127+
int64_t[:] counts,
128+
{{c_type}}[:, :] values,
129+
const int64_t[:] labels,
130130
Py_ssize_t min_count=-1):
131131
cdef:
132132
Py_ssize_t i, j, N, K, lab, ncounts = len(counts)
@@ -175,10 +175,10 @@ def group_var_{{name}}(ndarray[{{c_type}}, ndim=2] out,
175175

176176
@cython.wraparound(False)
177177
@cython.boundscheck(False)
178-
def group_mean_{{name}}(ndarray[{{c_type}}, ndim=2] out,
179-
ndarray[int64_t] counts,
180-
ndarray[{{c_type}}, ndim=2] values,
181-
ndarray[int64_t] labels,
178+
def group_mean_{{name}}({{c_type}}[:, :] out,
179+
int64_t[:] counts,
180+
{{c_type}}[:, :] values,
181+
const int64_t[:] labels,
182182
Py_ssize_t min_count=-1):
183183
cdef:
184184
Py_ssize_t i, j, N, K, lab, ncounts = len(counts)
@@ -220,11 +220,11 @@ def group_mean_{{name}}(ndarray[{{c_type}}, ndim=2] out,
220220

221221
@cython.wraparound(False)
222222
@cython.boundscheck(False)
223-
def group_ohlc_{{name}}(ndarray[{{c_type}}, ndim=2] out,
224-
ndarray[int64_t] counts,
225-
ndarray[{{c_type}}, ndim=2] values,
226-
ndarray[int64_t] labels,
227-
Py_ssize_t min_count=-1):
223+
def group_ohlc_{{name}}({{c_type}}[:, :] out,
224+
int64_t[:] counts,
225+
{{c_type}}[:, :] values,
226+
const int64_t[:] labels,
227+
Py_ssize_t min_count=-1):
228228
"""
229229
Only aggregates on axis=0
230230
"""
@@ -293,10 +293,10 @@ def get_dispatch(dtypes):
293293

294294
@cython.wraparound(False)
295295
@cython.boundscheck(False)
296-
def group_last_{{name}}(ndarray[{{c_type}}, ndim=2] out,
297-
ndarray[int64_t] counts,
298-
ndarray[{{c_type}}, ndim=2] values,
299-
ndarray[int64_t] labels,
296+
def group_last_{{name}}({{c_type}}[:, :] out,
297+
int64_t[:] counts,
298+
{{c_type}}[:, :] values,
299+
const int64_t[:] labels,
300300
Py_ssize_t min_count=-1):
301301
"""
302302
Only aggregates on axis=0
@@ -350,10 +350,10 @@ def group_last_{{name}}(ndarray[{{c_type}}, ndim=2] out,
350350

351351
@cython.wraparound(False)
352352
@cython.boundscheck(False)
353-
def group_nth_{{name}}(ndarray[{{c_type}}, ndim=2] out,
354-
ndarray[int64_t] counts,
355-
ndarray[{{c_type}}, ndim=2] values,
356-
ndarray[int64_t] labels, int64_t rank,
353+
def group_nth_{{name}}({{c_type}}[:, :] out,
354+
int64_t[:] counts,
355+
{{c_type}}[:, :] values,
356+
const int64_t[:] labels, int64_t rank,
357357
Py_ssize_t min_count=-1):
358358
"""
359359
Only aggregates on axis=0
@@ -411,9 +411,9 @@ def group_nth_{{name}}(ndarray[{{c_type}}, ndim=2] out,
411411

412412
@cython.boundscheck(False)
413413
@cython.wraparound(False)
414-
def group_rank_{{name}}(ndarray[float64_t, ndim=2] out,
415-
ndarray[{{c_type}}, ndim=2] values,
416-
ndarray[int64_t] labels,
414+
def group_rank_{{name}}(float64_t[:, :] out,
415+
{{c_type}}[:, :] values,
416+
const int64_t[:] labels,
417417
bint is_datetimelike, object ties_method,
418418
bint ascending, bint pct, object na_option):
419419
"""
@@ -606,10 +606,10 @@ ctypedef fused groupby_t:
606606

607607
@cython.wraparound(False)
608608
@cython.boundscheck(False)
609-
def group_max(ndarray[groupby_t, ndim=2] out,
610-
ndarray[int64_t] counts,
611-
ndarray[groupby_t, ndim=2] values,
612-
ndarray[int64_t] labels,
609+
def group_max(groupby_t[:, :] out,
610+
int64_t[:] counts,
611+
groupby_t[:, :] values,
612+
const int64_t[:] labels,
613613
Py_ssize_t min_count=-1):
614614
"""
615615
Only aggregates on axis=0
@@ -669,10 +669,10 @@ def group_max(ndarray[groupby_t, ndim=2] out,
669669

670670
@cython.wraparound(False)
671671
@cython.boundscheck(False)
672-
def group_min(ndarray[groupby_t, ndim=2] out,
673-
ndarray[int64_t] counts,
674-
ndarray[groupby_t, ndim=2] values,
675-
ndarray[int64_t] labels,
672+
def group_min(groupby_t[:, :] out,
673+
int64_t[:] counts,
674+
groupby_t[:, :] values,
675+
const int64_t[:] labels,
676676
Py_ssize_t min_count=-1):
677677
"""
678678
Only aggregates on axis=0
@@ -731,9 +731,9 @@ def group_min(ndarray[groupby_t, ndim=2] out,
731731

732732
@cython.boundscheck(False)
733733
@cython.wraparound(False)
734-
def group_cummin(ndarray[groupby_t, ndim=2] out,
735-
ndarray[groupby_t, ndim=2] values,
736-
ndarray[int64_t] labels,
734+
def group_cummin(groupby_t[:, :] out,
735+
groupby_t[:, :] values,
736+
const int64_t[:] labels,
737737
bint is_datetimelike):
738738
"""
739739
Only transforms on axis=0
@@ -779,9 +779,9 @@ def group_cummin(ndarray[groupby_t, ndim=2] out,
779779

780780
@cython.boundscheck(False)
781781
@cython.wraparound(False)
782-
def group_cummax(ndarray[groupby_t, ndim=2] out,
783-
ndarray[groupby_t, ndim=2] values,
784-
ndarray[int64_t] labels,
782+
def group_cummax(groupby_t[:, :] out,
783+
groupby_t[:, :] values,
784+
const int64_t[:] labels,
785785
bint is_datetimelike):
786786
"""
787787
Only transforms on axis=0

pandas/_libs/hashtable_class_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ cdef class {{name}}HashTable(HashTable):
322322
self.table.vals[k] = <Py_ssize_t>values[i]
323323

324324
@cython.boundscheck(False)
325-
def map_locations(self, ndarray[{{dtype}}_t, ndim=1] values):
325+
def map_locations(self, const {{dtype}}_t[:] values):
326326
cdef:
327327
Py_ssize_t i, n = len(values)
328328
int ret = 0

pandas/_libs/sparse_op_helper.pxi.in

+9-9
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ def get_dispatch(dtypes):
125125

126126
@cython.wraparound(False)
127127
@cython.boundscheck(False)
128-
cdef inline tuple block_op_{{opname}}_{{dtype}}(ndarray x_,
128+
cdef inline tuple block_op_{{opname}}_{{dtype}}({{dtype}}_t[:] x_,
129129
BlockIndex xindex,
130130
{{dtype}}_t xfill,
131-
ndarray y_,
131+
{{dtype}}_t[:] y_,
132132
BlockIndex yindex,
133133
{{dtype}}_t yfill):
134134
'''
@@ -142,7 +142,7 @@ cdef inline tuple block_op_{{opname}}_{{dtype}}(ndarray x_,
142142
int32_t xloc, yloc
143143
Py_ssize_t xblock = 0, yblock = 0 # block numbers
144144

145-
ndarray[{{dtype}}_t, ndim=1] x, y
145+
{{dtype}}_t[:] x, y
146146
ndarray[{{rdtype}}_t, ndim=1] out
147147

148148
# to suppress Cython warning
@@ -226,16 +226,16 @@ cdef inline tuple block_op_{{opname}}_{{dtype}}(ndarray x_,
226226

227227
@cython.wraparound(False)
228228
@cython.boundscheck(False)
229-
cdef inline tuple int_op_{{opname}}_{{dtype}}(ndarray x_, IntIndex xindex,
229+
cdef inline tuple int_op_{{opname}}_{{dtype}}({{dtype}}_t[:] x_, IntIndex xindex,
230230
{{dtype}}_t xfill,
231-
ndarray y_, IntIndex yindex,
231+
{{dtype}}_t[:] y_, IntIndex yindex,
232232
{{dtype}}_t yfill):
233233
cdef:
234234
IntIndex out_index
235235
Py_ssize_t xi = 0, yi = 0, out_i = 0 # fp buf indices
236236
int32_t xloc, yloc
237-
ndarray[int32_t, ndim=1] xindices, yindices, out_indices
238-
ndarray[{{dtype}}_t, ndim=1] x, y
237+
int32_t[:] xindices, yindices, out_indices
238+
{{dtype}}_t[:] x, y
239239
ndarray[{{rdtype}}_t, ndim=1] out
240240

241241
# suppress Cython compiler warnings due to inlining
@@ -284,9 +284,9 @@ cdef inline tuple int_op_{{opname}}_{{dtype}}(ndarray x_, IntIndex xindex,
284284
return out, out_index, {{(opname, 'xfill', 'yfill', dtype) | get_op}}
285285

286286

287-
cpdef sparse_{{opname}}_{{dtype}}(ndarray[{{dtype}}_t, ndim=1] x,
287+
cpdef sparse_{{opname}}_{{dtype}}({{dtype}}_t[:] x,
288288
SparseIndex xindex, {{dtype}}_t xfill,
289-
ndarray[{{dtype}}_t, ndim=1] y,
289+
{{dtype}}_t[:] y,
290290
SparseIndex yindex, {{dtype}}_t yfill):
291291

292292
if isinstance(xindex, BlockIndex):

0 commit comments

Comments
 (0)