Skip to content

Commit d660831

Browse files
authored
Remove inline from cython classes (#49873)
* removed inline class functions * removed all cdef inline * revert pxd * removed unused code * cython lint fixups
1 parent 2d185e1 commit d660831

28 files changed

+274
-290
lines changed

pandas/_libs/algos.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ tiebreakers = {
7070
}
7171

7272

73-
cdef inline bint are_diff(object left, object right):
73+
cdef bint are_diff(object left, object right):
7474
try:
7575
return fabs(left - right) > FP_ERR
7676
except TypeError:
@@ -257,7 +257,7 @@ def groupsort_indexer(const intp_t[:] index, Py_ssize_t ngroups):
257257
return indexer.base, counts.base
258258

259259

260-
cdef inline Py_ssize_t swap(numeric_t *a, numeric_t *b) nogil:
260+
cdef Py_ssize_t swap(numeric_t *a, numeric_t *b) nogil:
261261
cdef:
262262
numeric_t t
263263

@@ -268,7 +268,7 @@ cdef inline Py_ssize_t swap(numeric_t *a, numeric_t *b) nogil:
268268
return 0
269269

270270

271-
cdef inline numeric_t kth_smallest_c(numeric_t* arr, Py_ssize_t k, Py_ssize_t n) nogil:
271+
cdef numeric_t kth_smallest_c(numeric_t* arr, Py_ssize_t k, Py_ssize_t n) nogil:
272272
"""
273273
See kth_smallest.__doc__. The additional parameter n specifies the maximum
274274
number of elements considered in arr, needed for compatibility with usage

pandas/_libs/groupby.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ cdef enum InterpolationEnumType:
6060
INTERPOLATION_MIDPOINT
6161

6262

63-
cdef inline float64_t median_linear_mask(float64_t* a, int n, uint8_t* mask) nogil:
63+
cdef float64_t median_linear_mask(float64_t* a, int n, uint8_t* mask) nogil:
6464
cdef:
6565
int i, j, na_count = 0
6666
float64_t* tmp
@@ -97,7 +97,7 @@ cdef inline float64_t median_linear_mask(float64_t* a, int n, uint8_t* mask) nog
9797
return result
9898

9999

100-
cdef inline float64_t median_linear(float64_t* a, int n) nogil:
100+
cdef float64_t median_linear(float64_t* a, int n) nogil:
101101
cdef:
102102
int i, j, na_count = 0
103103
float64_t* tmp
@@ -134,7 +134,7 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil:
134134
return result
135135

136136

137-
cdef inline float64_t calc_median_linear(float64_t* a, int n, int na_count) nogil:
137+
cdef float64_t calc_median_linear(float64_t* a, int n, int na_count) nogil:
138138
cdef:
139139
float64_t result
140140

@@ -1231,7 +1231,7 @@ def group_quantile(
12311231
# group_nth, group_last, group_rank
12321232
# ----------------------------------------------------------------------
12331233

1234-
cdef inline bint _treat_as_na(numeric_object_t val, bint is_datetimelike) nogil:
1234+
cdef bint _treat_as_na(numeric_object_t val, bint is_datetimelike) nogil:
12351235
if numeric_object_t is object:
12361236
# Should never be used, but we need to avoid the `val != val` below
12371237
# or else cython will raise about gil acquisition.

pandas/_libs/hashing.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ def hash_object_array(
110110
return result.base # .base to retrieve underlying np.ndarray
111111

112112

113-
cdef inline uint64_t _rotl(uint64_t x, uint64_t b) nogil:
113+
cdef uint64_t _rotl(uint64_t x, uint64_t b) nogil:
114114
return (x << b) | (x >> (64 - b))
115115

116116

117-
cdef inline uint64_t u8to64_le(uint8_t* p) nogil:
117+
cdef uint64_t u8to64_le(uint8_t* p) nogil:
118118
return (<uint64_t>p[0] |
119119
<uint64_t>p[1] << 8 |
120120
<uint64_t>p[2] << 16 |
@@ -125,8 +125,8 @@ cdef inline uint64_t u8to64_le(uint8_t* p) nogil:
125125
<uint64_t>p[7] << 56)
126126

127127

128-
cdef inline void _sipround(uint64_t* v0, uint64_t* v1,
129-
uint64_t* v2, uint64_t* v3) nogil:
128+
cdef void _sipround(uint64_t* v0, uint64_t* v1,
129+
uint64_t* v2, uint64_t* v3) nogil:
130130
v0[0] += v1[0]
131131
v1[0] = _rotl(v1[0], 13)
132132
v1[0] ^= v0[0]

pandas/_libs/hashtable.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ cdef class Int64Vector(Vector):
185185

186186
cdef resize(self)
187187
cpdef ndarray to_array(self)
188-
cdef inline void append(self, int64_t x)
188+
cdef void append(self, int64_t x)
189189
cdef extend(self, int64_t[:] x)

pandas/_libs/hashtable_class_helper.pxi.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ ctypedef struct {{name}}VectorData:
140140

141141
@cython.wraparound(False)
142142
@cython.boundscheck(False)
143-
cdef inline void append_data_{{dtype}}({{name}}VectorData *data,
143+
cdef void append_data_{{dtype}}({{name}}VectorData *data,
144144
{{c_type}} x) nogil:
145145

146146
data.data[data.n] = x
@@ -163,7 +163,7 @@ ctypedef fused vector_data:
163163
Complex64VectorData
164164
StringVectorData
165165

166-
cdef inline bint needs_resize(vector_data *data) nogil:
166+
cdef bint needs_resize(vector_data *data) nogil:
167167
return data.n == data.m
168168

169169
# ----------------------------------------------------------------------
@@ -241,7 +241,7 @@ cdef class {{name}}Vector(Vector):
241241
self.external_view_exists = True
242242
return self.ao
243243

244-
cdef inline void append(self, {{c_type}} x):
244+
cdef void append(self, {{c_type}} x):
245245

246246
if needs_resize(self.data):
247247
if self.external_view_exists:
@@ -311,7 +311,7 @@ cdef class StringVector(Vector):
311311
self.data.m = self.data.n
312312
return ao
313313

314-
cdef inline void append(self, char *x):
314+
cdef void append(self, char *x):
315315

316316
if needs_resize(self.data):
317317
self.resize()
@@ -339,7 +339,7 @@ cdef class ObjectVector(Vector):
339339
def __len__(self) -> int:
340340
return self.n
341341

342-
cdef inline append(self, object obj):
342+
cdef append(self, object obj):
343343
if self.n == self.m:
344344
if self.external_view_exists:
345345
raise ValueError("external reference but "

pandas/_libs/index.pyx

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ from pandas._libs.missing cimport (
4040
multiindex_nulls_shift = 2
4141

4242

43-
cdef inline bint is_definitely_invalid_key(object val):
43+
cdef bint is_definitely_invalid_key(object val):
4444
try:
4545
hash(val)
4646
except TypeError:
@@ -176,7 +176,7 @@ cdef class IndexEngine:
176176
loc = self.values.searchsorted(self._np_type(val), side="left")
177177
return loc
178178

179-
cdef inline _get_loc_duplicates(self, object val):
179+
cdef _get_loc_duplicates(self, object val):
180180
# -> Py_ssize_t | slice | ndarray[bool]
181181
cdef:
182182
Py_ssize_t diff, left, right
@@ -225,7 +225,7 @@ cdef class IndexEngine:
225225

226226
return self.unique == 1
227227

228-
cdef inline _do_unique_check(self):
228+
cdef _do_unique_check(self):
229229

230230
# this de-facto the same
231231
self._ensure_mapping_populated()
@@ -244,7 +244,7 @@ cdef class IndexEngine:
244244

245245
return self.monotonic_dec == 1
246246

247-
cdef inline _do_monotonic_check(self):
247+
cdef _do_monotonic_check(self):
248248
cdef:
249249
bint is_unique
250250
try:
@@ -277,7 +277,7 @@ cdef class IndexEngine:
277277
def is_mapping_populated(self) -> bool:
278278
return self.mapping is not None
279279

280-
cdef inline _ensure_mapping_populated(self):
280+
cdef _ensure_mapping_populated(self):
281281
# this populates the mapping
282282
# if its not already populated
283283
# also satisfies the need_unique_check
@@ -932,7 +932,7 @@ cdef class SharedEngine:
932932

933933
return self._get_loc_duplicates(val)
934934

935-
cdef inline _get_loc_duplicates(self, object val):
935+
cdef _get_loc_duplicates(self, object val):
936936
# -> Py_ssize_t | slice | ndarray[bool]
937937
cdef:
938938
Py_ssize_t diff

0 commit comments

Comments
 (0)