Skip to content

Commit 2c164f0

Browse files
authored
MNT: Explicitly set cdef functions as noexcept (#53144)
* Explicitly set cdef functions as noexcept * Make linter happy
1 parent d8b1a45 commit 2c164f0

12 files changed

+32
-31
lines changed

pandas/_libs/groupby.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ cdef inline void _check_below_mincount(
13601360
int64_t[:, ::1] nobs,
13611361
int64_t min_count,
13621362
mincount_t[:, ::1] resx,
1363-
) nogil:
1363+
) noexcept nogil:
13641364
"""
13651365
Check if the number of observations for a group is below min_count,
13661366
and if so set the result for that group to the appropriate NA-like value.

pandas/_libs/hashing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ cdef uint64_t u8to64_le(uint8_t* p) nogil:
126126

127127

128128
cdef void _sipround(uint64_t* v0, uint64_t* v1,
129-
uint64_t* v2, uint64_t* v3) nogil:
129+
uint64_t* v2, uint64_t* v3) noexcept 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 void append(self, int64_t x)
188+
cdef void append(self, int64_t x) noexcept
189189
cdef extend(self, int64_t[:] x)

pandas/_libs/hashtable_class_helper.pxi.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ ctypedef struct {{name}}VectorData:
141141
@cython.wraparound(False)
142142
@cython.boundscheck(False)
143143
cdef void append_data_{{dtype}}({{name}}VectorData *data,
144-
{{c_type}} x) nogil:
144+
{{c_type}} x) noexcept nogil:
145145

146146
data.data[data.n] = x
147147
data.n += 1
@@ -241,7 +241,7 @@ cdef class {{name}}Vector(Vector):
241241
self.external_view_exists = True
242242
return self.ao
243243

244-
cdef void append(self, {{c_type}} x):
244+
cdef void append(self, {{c_type}} x) noexcept:
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 void append(self, char *x):
314+
cdef void append(self, char *x) noexcept:
315315

316316
if needs_resize(self.data):
317317
self.resize()

pandas/_libs/join.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def full_outer_join(const intp_t[:] left, const intp_t[:] right,
213213

214214
@cython.wraparound(False)
215215
@cython.boundscheck(False)
216-
cdef void _get_result_indexer(intp_t[::1] sorter, intp_t[::1] indexer) nogil:
216+
cdef void _get_result_indexer(intp_t[::1] sorter, intp_t[::1] indexer) noexcept nogil:
217217
"""NOTE: overwrites indexer with the result to avoid allocating another array"""
218218
cdef:
219219
Py_ssize_t i, n, idx

pandas/_libs/tslibs/conversion.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ cdef check_overflows(_TSObject obj, NPY_DATETIMEUNIT reso=NPY_FR_ns):
595595
# ----------------------------------------------------------------------
596596
# Localization
597597

598-
cdef void _localize_tso(_TSObject obj, tzinfo tz, NPY_DATETIMEUNIT reso):
598+
cdef void _localize_tso(_TSObject obj, tzinfo tz, NPY_DATETIMEUNIT reso) noexcept:
599599
"""
600600
Given the UTC nanosecond timestamp in obj.value, find the wall-clock
601601
representation of that timestamp in the given timezone.

pandas/_libs/tslibs/np_datetime.pxd

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ cdef extern from "src/datetime/pd_datetime.h":
8080
INFER_FORMAT
8181

8282
# You must call this before using the PandasDateTime CAPI functions
83-
cdef inline void import_pandas_datetime():
83+
cdef inline void import_pandas_datetime() noexcept:
8484
PandasDateTime_IMPORT
8585

8686
cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1
@@ -90,11 +90,11 @@ cdef check_dts_bounds(npy_datetimestruct *dts, NPY_DATETIMEUNIT unit=?)
9090
cdef int64_t pydatetime_to_dt64(
9191
datetime val, npy_datetimestruct *dts, NPY_DATETIMEUNIT reso=?
9292
)
93-
cdef void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts)
93+
cdef void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts) noexcept
9494
cdef int64_t pydate_to_dt64(
9595
date val, npy_datetimestruct *dts, NPY_DATETIMEUNIT reso=?
9696
)
97-
cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts)
97+
cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts) noexcept
9898

9999
cdef npy_datetime get_datetime64_value(object obj) nogil
100100
cdef npy_timedelta get_timedelta64_value(object obj) nogil

pandas/_libs/tslibs/np_datetime.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def py_td64_to_tdstruct(int64_t td64, NPY_DATETIMEUNIT unit):
229229
return tds # <- returned as a dict to python
230230

231231

232-
cdef void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts):
232+
cdef void pydatetime_to_dtstruct(datetime dt, npy_datetimestruct *dts) noexcept:
233233
if PyDateTime_CheckExact(dt):
234234
dts.year = PyDateTime_GET_YEAR(dt)
235235
else:
@@ -256,7 +256,7 @@ cdef int64_t pydatetime_to_dt64(datetime val,
256256
return npy_datetimestruct_to_datetime(reso, dts)
257257

258258

259-
cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts):
259+
cdef void pydate_to_dtstruct(date val, npy_datetimestruct *dts) noexcept:
260260
dts.year = PyDateTime_GET_YEAR(val)
261261
dts.month = PyDateTime_GET_MONTH(val)
262262
dts.day = PyDateTime_GET_DAY(val)

pandas/_libs/tslibs/parsing.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ cdef str _fill_token(token: str, padding: int):
10521052
return token_filled
10531053

10541054

1055-
cdef void _maybe_warn_about_dayfirst(format: str, bint dayfirst):
1055+
cdef void _maybe_warn_about_dayfirst(format: str, bint dayfirst) noexcept:
10561056
"""Warn if guessed datetime format doesn't respect dayfirst argument."""
10571057
cdef:
10581058
int day_index = format.find("%d")

pandas/_libs/tslibs/period.pyx

+6-5
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ cdef int get_freq_group_index(int freq) nogil:
691691
return freq // 1000
692692

693693

694-
cdef void adjust_dts_for_month(npy_datetimestruct* dts, int from_end) nogil:
694+
cdef void adjust_dts_for_month(npy_datetimestruct* dts, int from_end) noexcept nogil:
695695
if from_end != 12:
696696
dts.month += from_end
697697
if dts.month > 12:
@@ -700,7 +700,7 @@ cdef void adjust_dts_for_month(npy_datetimestruct* dts, int from_end) nogil:
700700
dts.year -= 1
701701

702702

703-
cdef void adjust_dts_for_qtr(npy_datetimestruct* dts, int to_end) nogil:
703+
cdef void adjust_dts_for_qtr(npy_datetimestruct* dts, int to_end) noexcept nogil:
704704
if to_end != 12:
705705
dts.month -= to_end
706706
if dts.month <= 0:
@@ -803,7 +803,8 @@ cdef int64_t get_period_ordinal(npy_datetimestruct *dts, int freq) nogil:
803803
return npy_datetimestruct_to_datetime(unit, dts)
804804

805805

806-
cdef void get_date_info(int64_t ordinal, int freq, npy_datetimestruct *dts) nogil:
806+
cdef void get_date_info(int64_t ordinal,
807+
int freq, npy_datetimestruct *dts) noexcept nogil:
807808
cdef:
808809
int64_t unix_date, nanos
809810
npy_datetimestruct dts2
@@ -985,7 +986,7 @@ def periodarr_to_dt64arr(const int64_t[:] periodarr, int freq):
985986

986987

987988
cdef void get_asfreq_info(int from_freq, int to_freq,
988-
bint is_end, asfreq_info *af_info) nogil:
989+
bint is_end, asfreq_info *af_info) noexcept nogil:
989990
"""
990991
Construct the `asfreq_info` object used to convert an ordinal from
991992
`from_freq` to `to_freq`.
@@ -1084,7 +1085,7 @@ cdef void _period_asfreq(
10841085
int freq2,
10851086
bint end,
10861087
Py_ssize_t increment=1,
1087-
):
1088+
) noexcept:
10881089
"""See period_asfreq.__doc__"""
10891090
cdef:
10901091
Py_ssize_t i

pandas/_libs/tslibs/util.pxd

+11-11
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ cdef extern from "numpy/npy_common.h":
4444
int64_t NPY_MIN_INT64
4545

4646

47-
cdef inline int64_t get_nat():
47+
cdef inline int64_t get_nat() noexcept:
4848
return NPY_MIN_INT64
4949

5050

5151
# --------------------------------------------------------------------
5252
# Type Checking
5353

54-
cdef inline bint is_integer_object(object obj) nogil:
54+
cdef inline bint is_integer_object(object obj) noexcept nogil:
5555
"""
5656
Cython equivalent of
5757
@@ -73,7 +73,7 @@ cdef inline bint is_integer_object(object obj) nogil:
7373
and not is_timedelta64_object(obj))
7474

7575

76-
cdef inline bint is_float_object(object obj) nogil:
76+
cdef inline bint is_float_object(object obj) noexcept nogil:
7777
"""
7878
Cython equivalent of `isinstance(val, (float, np.float_))`
7979
@@ -89,7 +89,7 @@ cdef inline bint is_float_object(object obj) nogil:
8989
(PyObject_TypeCheck(obj, &PyFloatingArrType_Type)))
9090

9191

92-
cdef inline bint is_complex_object(object obj) nogil:
92+
cdef inline bint is_complex_object(object obj) noexcept nogil:
9393
"""
9494
Cython equivalent of `isinstance(val, (complex, np.complex_))`
9595
@@ -105,7 +105,7 @@ cdef inline bint is_complex_object(object obj) nogil:
105105
PyObject_TypeCheck(obj, &PyComplexFloatingArrType_Type))
106106

107107

108-
cdef inline bint is_bool_object(object obj) nogil:
108+
cdef inline bint is_bool_object(object obj) noexcept nogil:
109109
"""
110110
Cython equivalent of `isinstance(val, (bool, np.bool_))`
111111
@@ -121,11 +121,11 @@ cdef inline bint is_bool_object(object obj) nogil:
121121
PyObject_TypeCheck(obj, &PyBoolArrType_Type))
122122

123123

124-
cdef inline bint is_real_number_object(object obj) nogil:
124+
cdef inline bint is_real_number_object(object obj) noexcept nogil:
125125
return is_bool_object(obj) or is_integer_object(obj) or is_float_object(obj)
126126

127127

128-
cdef inline bint is_timedelta64_object(object obj) nogil:
128+
cdef inline bint is_timedelta64_object(object obj) noexcept nogil:
129129
"""
130130
Cython equivalent of `isinstance(val, np.timedelta64)`
131131
@@ -140,7 +140,7 @@ cdef inline bint is_timedelta64_object(object obj) nogil:
140140
return PyObject_TypeCheck(obj, &PyTimedeltaArrType_Type)
141141

142142

143-
cdef inline bint is_datetime64_object(object obj) nogil:
143+
cdef inline bint is_datetime64_object(object obj) noexcept nogil:
144144
"""
145145
Cython equivalent of `isinstance(val, np.datetime64)`
146146
@@ -155,7 +155,7 @@ cdef inline bint is_datetime64_object(object obj) nogil:
155155
return PyObject_TypeCheck(obj, &PyDatetimeArrType_Type)
156156

157157

158-
cdef inline bint is_array(object val):
158+
cdef inline bint is_array(object val) noexcept:
159159
"""
160160
Cython equivalent of `isinstance(val, np.ndarray)`
161161
@@ -217,11 +217,11 @@ cdef inline const char* get_c_string(str py_string) except NULL:
217217
return get_c_string_buf_and_size(py_string, NULL)
218218

219219

220-
cdef inline bytes string_encode_locale(str py_string):
220+
cdef inline bytes string_encode_locale(str py_string) noexcept:
221221
"""As opposed to PyUnicode_Encode, use current system locale to encode."""
222222
return PyUnicode_EncodeLocale(py_string, NULL)
223223

224224

225-
cdef inline object char_to_string_locale(const char* data):
225+
cdef inline object char_to_string_locale(const char* data) noexcept:
226226
"""As opposed to PyUnicode_FromString, use current system locale to decode."""
227227
return PyUnicode_DecodeLocale(data, NULL)

pandas/_libs/window/aggregations.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cdef float64_t calc_sum(int64_t minp, int64_t nobs, float64_t sum_x,
8989

9090
cdef void add_sum(float64_t val, int64_t *nobs, float64_t *sum_x,
9191
float64_t *compensation, int64_t *num_consecutive_same_value,
92-
float64_t *prev_value) nogil:
92+
float64_t *prev_value) noexcept nogil:
9393
""" add a value from the sum calc using Kahan summation """
9494

9595
cdef:

0 commit comments

Comments
 (0)