Skip to content

Remove inline from cython classes #49873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/hashtable.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ cdef class Int64Vector(Vector):

cdef resize(self)
cpdef ndarray to_array(self)
cdef inline void append(self, int64_t x)
cdef void append(self, int64_t x)
cdef extend(self, int64_t[:] x)
6 changes: 3 additions & 3 deletions pandas/_libs/hashtable_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ cdef class {{name}}Vector(Vector):
self.external_view_exists = True
return self.ao

cdef inline void append(self, {{c_type}} x):
cdef void append(self, {{c_type}} x):

if needs_resize(self.data):
if self.external_view_exists:
Expand Down Expand Up @@ -311,7 +311,7 @@ cdef class StringVector(Vector):
self.data.m = self.data.n
return ao

cdef inline void append(self, char *x):
cdef void append(self, char *x):

if needs_resize(self.data):
self.resize()
Expand Down Expand Up @@ -339,7 +339,7 @@ cdef class ObjectVector(Vector):
def __len__(self) -> int:
return self.n

cdef inline append(self, object obj):
cdef append(self, object obj):
if self.n == self.m:
if self.external_view_exists:
raise ValueError("external reference but "
Expand Down
10 changes: 5 additions & 5 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ cdef class IndexEngine:
loc = self.values.searchsorted(self._np_type(val), side="left")
return loc

cdef inline _get_loc_duplicates(self, object val):
cdef _get_loc_duplicates(self, object val):
# -> Py_ssize_t | slice | ndarray[bool]
cdef:
Py_ssize_t diff, left, right
Expand Down Expand Up @@ -225,7 +225,7 @@ cdef class IndexEngine:

return self.unique == 1

cdef inline _do_unique_check(self):
cdef _do_unique_check(self):

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

return self.monotonic_dec == 1

cdef inline _do_monotonic_check(self):
cdef _do_monotonic_check(self):
cdef:
bint is_unique
try:
Expand Down Expand Up @@ -277,7 +277,7 @@ cdef class IndexEngine:
def is_mapping_populated(self) -> bool:
return self.mapping is not None

cdef inline _ensure_mapping_populated(self):
cdef _ensure_mapping_populated(self):
# this populates the mapping
# if its not already populated
# also satisfies the need_unique_check
Expand Down Expand Up @@ -932,7 +932,7 @@ cdef class SharedEngine:

return self._get_loc_duplicates(val)

cdef inline _get_loc_duplicates(self, object val):
cdef _get_loc_duplicates(self, object val):
# -> Py_ssize_t | slice | ndarray[bool]
cdef:
Py_ssize_t diff
Expand Down
54 changes: 27 additions & 27 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ cdef class Seen:
self.interval_ = False
self.coerce_numeric = coerce_numeric

cdef inline bint check_uint64_conflict(self) except -1:
cdef bint check_uint64_conflict(self) except -1:
"""
Check whether we can safely convert a uint64 array to a numeric dtype.

Expand Down Expand Up @@ -1240,7 +1240,7 @@ cdef class Seen:
return (self.uint_ and (self.null_ or self.sint_)
and not self.coerce_numeric)

cdef inline saw_null(self):
cdef saw_null(self):
"""
Set flags indicating that a null value was encountered.
"""
Expand Down Expand Up @@ -1655,10 +1655,10 @@ cdef class Validator:

@cython.internal
cdef class BoolValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return util.is_bool_object(value)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.bool_)


Expand All @@ -1672,10 +1672,10 @@ cpdef bint is_bool_array(ndarray values, bint skipna=False):

@cython.internal
cdef class IntegerValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return util.is_integer_object(value)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.integer)


Expand All @@ -1690,7 +1690,7 @@ cpdef bint is_integer_array(ndarray values, bint skipna=True):

@cython.internal
cdef class IntegerNaValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return (util.is_integer_object(value)
or (util.is_nan(value) and util.is_float_object(value)))

Expand All @@ -1704,10 +1704,10 @@ cdef bint is_integer_na_array(ndarray values, bint skipna=True):

@cython.internal
cdef class IntegerFloatValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return util.is_integer_object(value) or util.is_float_object(value)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.integer)


Expand All @@ -1721,10 +1721,10 @@ cdef bint is_integer_float_array(ndarray values, bint skipna=True):

@cython.internal
cdef class FloatValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return util.is_float_object(value)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.floating)


Expand All @@ -1737,13 +1737,13 @@ cpdef bint is_float_array(ndarray values):

@cython.internal
cdef class ComplexValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return (
util.is_complex_object(value)
or (util.is_float_object(value) and is_nan(value))
)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.complexfloating)


Expand All @@ -1755,7 +1755,7 @@ cdef bint is_complex_array(ndarray values):

@cython.internal
cdef class DecimalValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return is_decimal(value)


Expand All @@ -1769,10 +1769,10 @@ cdef bint is_decimal_array(ndarray values, bint skipna=False):

@cython.internal
cdef class StringValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return isinstance(value, str)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.str_)


Expand All @@ -1786,10 +1786,10 @@ cpdef bint is_string_array(ndarray values, bint skipna=False):

@cython.internal
cdef class BytesValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return isinstance(value, bytes)

cdef inline bint is_array_typed(self) except -1:
cdef bint is_array_typed(self) except -1:
return issubclass(self.dtype.type, np.bytes_)


Expand All @@ -1812,14 +1812,14 @@ cdef class TemporalValidator(Validator):
self.skipna = skipna
self.all_generic_na = True

cdef inline bint is_valid(self, object value) except -1:
cdef bint is_valid(self, object value) except -1:
return self.is_value_typed(value) or self.is_valid_null(value)

cdef bint is_valid_null(self, object value) except -1:
raise NotImplementedError(f"{type(self).__name__} child class "
"must define is_valid_null")

cdef inline bint is_valid_skipna(self, object value) except -1:
cdef bint is_valid_skipna(self, object value) except -1:
cdef:
bint is_typed_null = self.is_valid_null(value)
bint is_generic_null = value is None or util.is_nan(value)
Expand All @@ -1840,7 +1840,7 @@ cdef class DatetimeValidator(TemporalValidator):
cdef bint is_value_typed(self, object value) except -1:
return PyDateTime_Check(value)

cdef inline bint is_valid_null(self, object value) except -1:
cdef bint is_valid_null(self, object value) except -1:
return is_null_datetime64(value)


Expand All @@ -1853,7 +1853,7 @@ cpdef bint is_datetime_array(ndarray values, bint skipna=True):

@cython.internal
cdef class Datetime64Validator(DatetimeValidator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return util.is_datetime64_object(value)


Expand All @@ -1867,7 +1867,7 @@ cpdef bint is_datetime64_array(ndarray values, bint skipna=True):

@cython.internal
cdef class AnyDatetimeValidator(DatetimeValidator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return util.is_datetime64_object(value) or (
PyDateTime_Check(value) and value.tzinfo is None
)
Expand Down Expand Up @@ -1919,13 +1919,13 @@ cdef class TimedeltaValidator(TemporalValidator):
cdef bint is_value_typed(self, object value) except -1:
return PyDelta_Check(value)

cdef inline bint is_valid_null(self, object value) except -1:
cdef bint is_valid_null(self, object value) except -1:
return is_null_timedelta64(value)


@cython.internal
cdef class AnyTimedeltaValidator(TimedeltaValidator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return is_timedelta(value)


Expand All @@ -1942,7 +1942,7 @@ cpdef bint is_timedelta_or_timedelta64_array(ndarray values, bint skipna=True):

@cython.internal
cdef class DateValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return PyDate_Check(value)


Expand All @@ -1955,7 +1955,7 @@ cpdef bint is_date_array(ndarray values, bint skipna=False):

@cython.internal
cdef class TimeValidator(Validator):
cdef inline bint is_value_typed(self, object value) except -1:
cdef bint is_value_typed(self, object value) except -1:
return PyTime_Check(value)


Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ cdef class TextReader:
return results

# -> tuple["ArrayLike", int]:
cdef inline _convert_tokens(self, Py_ssize_t i, int64_t start,
cdef _convert_tokens(self, Py_ssize_t i, int64_t start,
int64_t end, object name, bint na_filter,
kh_str_starts_t *na_hashset,
object na_flist, object col_dtype):
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ cdef class _Timedelta(timedelta):
cdef bint _has_ns(self)
cdef bint _is_in_pytimedelta_bounds(self)
cdef _ensure_components(_Timedelta self)
cdef inline bint _compare_mismatched_resos(self, _Timedelta other, op)
cdef bint _compare_mismatched_resos(self, _Timedelta other, op)
cdef _Timedelta _as_creso(self, NPY_DATETIMEUNIT reso, bint round_ok=*)
cpdef _maybe_cast_to_matching_resos(self, _Timedelta other)
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ cdef class _Timedelta(timedelta):
return self._compare_mismatched_resos(ots, op)

# TODO: re-use/share with Timestamp
cdef inline bint _compare_mismatched_resos(self, _Timedelta other, op):
cdef bint _compare_mismatched_resos(self, _Timedelta other, op):
# Can't just dispatch to numpy as they silently overflow and get it wrong
cdef:
npy_datetimestruct dts_self
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ cdef class _Timestamp(ABCTimestamp):
return self._compare_mismatched_resos(ots, op)

# TODO: copied from Timedelta; try to de-duplicate
cdef inline bint _compare_mismatched_resos(self, _Timestamp other, int op):
cdef bint _compare_mismatched_resos(self, _Timestamp other, int op):
# Can't just dispatch to numpy as they silently overflow and get it wrong
cdef:
npy_datetimestruct dts_self
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/tzconversion.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cdef class Localizer:
int64_t delta
int64_t* tdata

cdef inline int64_t utc_val_to_local_val(
cdef int64_t utc_val_to_local_val(
self,
int64_t utc_val,
Py_ssize_t* pos,
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/tzconversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ cdef class Localizer:
self.tdata = <int64_t*>cnp.PyArray_DATA(trans)

@cython.boundscheck(False)
cdef inline int64_t utc_val_to_local_val(
cdef int64_t utc_val_to_local_val(
self, int64_t utc_val, Py_ssize_t* pos, bint* fold=NULL
) except? -1:
if self.use_utc:
Expand Down