Skip to content

Commit e5301a8

Browse files
DEP: Use Cython 3.0 (#55179)
* DEP: Use Cython 3.0 * Cython 3.0.3 * Update to Cython 3.0.4 * Merge pyi updates * fixup * Update pyi files and upgrade to Cython 3.0.5 * Remove debug print * fix typo --------- Co-authored-by: Thomas Li <[email protected]>
1 parent 02e2bae commit e5301a8

24 files changed

+54
-41
lines changed

asv_bench/asv.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// pip (with all the conda available packages installed first,
4242
// followed by the pip installed packages).
4343
"matrix": {
44-
"Cython": ["0.29.33"],
44+
"Cython": ["3.0.5"],
4545
"matplotlib": [],
4646
"sqlalchemy": [],
4747
"scipy": [],

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88

99
# build dependencies
1010
- versioneer[toml]
11-
- cython=0.29.33
11+
- cython=3.0.5
1212
- meson[ninja]=1.2.1
1313
- meson-python=0.13.1
1414

pandas/_libs/arrays.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class NDArrayBacked:
2626
def size(self) -> int: ...
2727
@property
2828
def nbytes(self) -> int: ...
29-
def copy(self): ...
29+
def copy(self, order=...): ...
3030
def delete(self, loc, axis=...): ...
3131
def swapaxes(self, axis1, axis2): ...
3232
def repeat(self, repeats: int | Sequence[int], axis: int | None = ...): ...

pandas/_libs/groupby.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def group_fillna_indexer(
4444
labels: np.ndarray, # ndarray[int64_t]
4545
sorted_labels: npt.NDArray[np.intp],
4646
mask: npt.NDArray[np.uint8],
47-
direction: Literal["ffill", "bfill"],
4847
limit: int, # int64_t
4948
dropna: bool,
5049
) -> None: ...
@@ -55,7 +54,7 @@ def group_any_all(
5554
mask: np.ndarray, # const uint8_t[::1]
5655
val_test: Literal["any", "all"],
5756
skipna: bool,
58-
nullable: bool,
57+
result_mask: np.ndarray | None,
5958
) -> None: ...
6059
def group_sum(
6160
out: np.ndarray, # complexfloatingintuint_t[:, ::1]

pandas/_libs/hashtable.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Factorizer:
2020
def factorize(
2121
self,
2222
values: np.ndarray,
23-
sort: bool = ...,
2423
na_sentinel=...,
2524
na_value=...,
2625
mask=...,
@@ -157,9 +156,9 @@ class HashTable:
157156
def __contains__(self, key: Hashable) -> bool: ...
158157
def sizeof(self, deep: bool = ...) -> int: ...
159158
def get_state(self) -> dict[str, int]: ...
160-
# TODO: `item` type is subclass-specific
161-
def get_item(self, item): ... # TODO: return type?
162-
def set_item(self, item, val) -> None: ...
159+
# TODO: `val/key` type is subclass-specific
160+
def get_item(self, val): ... # TODO: return type?
161+
def set_item(self, key, val) -> None: ...
163162
def get_na(self): ... # TODO: return type?
164163
def set_na(self, val) -> None: ...
165164
def map_locations(
@@ -185,6 +184,7 @@ class HashTable:
185184
self,
186185
values: np.ndarray, # np.ndarray[subclass-specific]
187186
return_inverse: bool = ...,
187+
mask=...,
188188
) -> (
189189
tuple[
190190
np.ndarray, # np.ndarray[subclass-specific]
@@ -198,6 +198,7 @@ class HashTable:
198198
na_sentinel: int = ...,
199199
na_value: object = ...,
200200
mask=...,
201+
ignore_na: bool = True,
201202
) -> tuple[np.ndarray, npt.NDArray[np.intp]]: ... # np.ndarray[subclass-specific]
202203

203204
class Complex128HashTable(HashTable): ...

pandas/_libs/hashtable_class_helper.pxi.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,9 +1239,10 @@ cdef class StringHashTable(HashTable):
12391239
na_value=na_value, ignore_na=ignore_na,
12401240
return_inverse=True)
12411241

1242+
# Add unused mask parameter for compat with other signatures
12421243
def get_labels(self, ndarray[object] values, ObjectVector uniques,
12431244
Py_ssize_t count_prior=0, Py_ssize_t na_sentinel=-1,
1244-
object na_value=None):
1245+
object na_value=None, object mask=None):
12451246
# -> np.ndarray[np.intp]
12461247
_, labels = self._unique(values, uniques, count_prior=count_prior,
12471248
na_sentinel=na_sentinel, na_value=na_value,
@@ -1496,9 +1497,10 @@ cdef class PyObjectHashTable(HashTable):
14961497
na_value=na_value, ignore_na=ignore_na,
14971498
return_inverse=True)
14981499

1500+
# Add unused mask parameter for compat with other signatures
14991501
def get_labels(self, ndarray[object] values, ObjectVector uniques,
15001502
Py_ssize_t count_prior=0, Py_ssize_t na_sentinel=-1,
1501-
object na_value=None):
1503+
object na_value=None, object mask=None):
15021504
# -> np.ndarray[np.intp]
15031505
_, labels = self._unique(values, uniques, count_prior=count_prior,
15041506
na_sentinel=na_sentinel, na_value=na_value,

pandas/_libs/lib.pyi

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@ def is_scalar(val: object) -> bool: ...
4545
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ...
4646
def is_pyarrow_array(obj: object) -> bool: ...
4747
def is_period(val: object) -> TypeGuard[Period]: ...
48-
def is_interval(val: object) -> TypeGuard[Interval]: ...
49-
def is_decimal(val: object) -> TypeGuard[Decimal]: ...
50-
def is_complex(val: object) -> TypeGuard[complex]: ...
51-
def is_bool(val: object) -> TypeGuard[bool | np.bool_]: ...
52-
def is_integer(val: object) -> TypeGuard[int | np.integer]: ...
48+
def is_interval(obj: object) -> TypeGuard[Interval]: ...
49+
def is_decimal(obj: object) -> TypeGuard[Decimal]: ...
50+
def is_complex(obj: object) -> TypeGuard[complex]: ...
51+
def is_bool(obj: object) -> TypeGuard[bool | np.bool_]: ...
52+
def is_integer(obj: object) -> TypeGuard[int | np.integer]: ...
5353
def is_int_or_none(obj) -> bool: ...
54-
def is_float(val: object) -> TypeGuard[float]: ...
54+
def is_float(obj: object) -> TypeGuard[float]: ...
5555
def is_interval_array(values: np.ndarray) -> bool: ...
56-
def is_datetime64_array(values: np.ndarray) -> bool: ...
57-
def is_timedelta_or_timedelta64_array(values: np.ndarray) -> bool: ...
56+
def is_datetime64_array(values: np.ndarray, skipna: bool = True) -> bool: ...
57+
def is_timedelta_or_timedelta64_array(
58+
values: np.ndarray, skipna: bool = True
59+
) -> bool: ...
5860
def is_datetime_with_singletz_array(values: np.ndarray) -> bool: ...
5961
def is_time_array(values: np.ndarray, skipna: bool = ...): ...
6062
def is_date_array(values: np.ndarray, skipna: bool = ...): ...
6163
def is_datetime_array(values: np.ndarray, skipna: bool = ...): ...
6264
def is_string_array(values: np.ndarray, skipna: bool = ...): ...
63-
def is_float_array(values: np.ndarray, skipna: bool = ...): ...
65+
def is_float_array(values: np.ndarray): ...
6466
def is_integer_array(values: np.ndarray, skipna: bool = ...): ...
6567
def is_bool_array(values: np.ndarray, skipna: bool = ...): ...
6668
def fast_multiget(
@@ -185,7 +187,7 @@ def count_level_2d(
185187
max_bin: int,
186188
) -> np.ndarray: ... # np.ndarray[np.int64, ndim=2]
187189
def get_level_sorter(
188-
label: np.ndarray, # const int64_t[:]
190+
codes: np.ndarray, # const int64_t[:]
189191
starts: np.ndarray, # const intp_t[:]
190192
) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1]
191193
def generate_bins_dt64(

pandas/_libs/ops.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def vec_binop(
3737
@overload
3838
def maybe_convert_bool(
3939
arr: npt.NDArray[np.object_],
40-
true_values: Iterable = ...,
41-
false_values: Iterable = ...,
40+
true_values: Iterable | None = None,
41+
false_values: Iterable | None = None,
4242
convert_to_masked_nullable: Literal[False] = ...,
4343
) -> tuple[np.ndarray, None]: ...
4444
@overload

pandas/_libs/sparse.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class BlockIndex(SparseIndex):
3939
self, length: int, blocs: np.ndarray, blengths: np.ndarray
4040
) -> None: ...
4141

42+
# Override to have correct parameters
43+
def intersect(self, other: SparseIndex) -> Self: ...
44+
def make_union(self, y: SparseIndex) -> Self: ...
45+
4246
def make_mask_object_ndarray(
4347
arr: npt.NDArray[np.object_], fill_value
4448
) -> npt.NDArray[np.bool_]: ...

pandas/_libs/tslibs/conversion.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ DT64NS_DTYPE: np.dtype
99
TD64NS_DTYPE: np.dtype
1010

1111
def precision_from_unit(
12-
in_reso: int, # NPY_DATETIMEUNIT
12+
in_reso: int,
13+
out_reso: int = ...,
1314
) -> tuple[int, int]: ... # (int64_t, _)
1415
def localize_pydatetime(dt: datetime, tz: tzinfo | None) -> datetime: ...

pandas/_libs/tslibs/dtypes.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ from enum import Enum
22

33
OFFSET_TO_PERIOD_FREQSTR: dict[str, str]
44

5-
def periods_per_day(reso: int) -> int: ...
5+
def periods_per_day(reso: int = ...) -> int: ...
66
def periods_per_second(reso: int) -> int: ...
77
def is_supported_unit(reso: int) -> bool: ...
8-
def npy_unit_to_abbrev(reso: int) -> str: ...
8+
def npy_unit_to_abbrev(unit: int) -> str: ...
99
def get_supported_reso(reso: int) -> int: ...
1010
def abbrev_to_npy_unit(abbrev: str) -> int: ...
1111
def freq_to_period_freqstr(freq_n: int, freq_name: str) -> str: ...

pandas/_libs/tslibs/np_datetime.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class OutOfBoundsTimedelta(ValueError): ...
99
def py_get_unit_from_dtype(dtype: np.dtype): ...
1010
def py_td64_to_tdstruct(td64: int, unit: int) -> dict: ...
1111
def astype_overflowsafe(
12-
arr: np.ndarray,
12+
values: np.ndarray,
1313
dtype: np.dtype,
1414
copy: bool = ...,
1515
round_ok: bool = ...,

pandas/_libs/tslibs/period.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Period(PeriodMixin):
8989
@classmethod
9090
def _from_ordinal(cls, ordinal: int, freq) -> Period: ...
9191
@classmethod
92-
def now(cls, freq: Frequency = ...) -> Period: ...
92+
def now(cls, freq: Frequency) -> Period: ...
9393
def strftime(self, fmt: str | None) -> str: ...
9494
def to_timestamp(
9595
self,

pandas/_libs/tslibs/strptime.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def array_strptime(
88
exact: bool = ...,
99
errors: str = ...,
1010
utc: bool = ...,
11+
creso: int = ..., # NPY_DATETIMEUNIT
1112
) -> tuple[np.ndarray, np.ndarray]: ...
1213

1314
# first ndarray is M8[ns], second is object ndarray of tzinfo | None

pandas/_libs/tslibs/timedeltas.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ _S = TypeVar("_S", bound=timedelta)
7171
def get_unit_for_round(freq, creso: int) -> int: ...
7272
def disallow_ambiguous_unit(unit: str | None) -> None: ...
7373
def ints_to_pytimedelta(
74-
arr: npt.NDArray[np.timedelta64],
74+
m8values: npt.NDArray[np.timedelta64],
7575
box: bool = ...,
7676
) -> npt.NDArray[np.object_]: ...
7777
def array_to_timedelta64(
@@ -165,8 +165,10 @@ class Timedelta(timedelta):
165165
def __gt__(self, other: timedelta) -> bool: ...
166166
def __hash__(self) -> int: ...
167167
def isoformat(self) -> str: ...
168-
def to_numpy(self) -> np.timedelta64: ...
169-
def view(self, dtype: npt.DTypeLike = ...) -> object: ...
168+
def to_numpy(
169+
self, dtype: npt.DTypeLike = ..., copy: bool = False
170+
) -> np.timedelta64: ...
171+
def view(self, dtype: npt.DTypeLike) -> object: ...
170172
@property
171173
def unit(self) -> str: ...
172174
def as_unit(self, unit: str, round_ok: bool = ...) -> Timedelta: ...

pandas/_libs/tslibs/timestamps.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Timestamp(datetime):
183183
def is_year_end(self) -> bool: ...
184184
def to_pydatetime(self, warn: bool = ...) -> datetime: ...
185185
def to_datetime64(self) -> np.datetime64: ...
186-
def to_period(self, freq: BaseOffset | str = ...) -> Period: ...
186+
def to_period(self, freq: BaseOffset | str | None = None) -> Period: ...
187187
def to_julian_date(self) -> np.float64: ...
188188
@property
189189
def asm8(self) -> np.datetime64: ...

pandas/_libs/tslibs/tzconversion.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from pandas._typing import npt
1010

1111
# tz_convert_from_utc_single exposed for testing
1212
def tz_convert_from_utc_single(
13-
val: np.int64, tz: tzinfo, creso: int = ...
13+
utc_val: np.int64, tz: tzinfo, creso: int = ...
1414
) -> np.int64: ...
1515
def tz_localize_to_utc(
1616
vals: npt.NDArray[np.int64],

pandas/_libs/tslibs/vectorized.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_resolution(
3131
reso: int = ..., # NPY_DATETIMEUNIT
3232
) -> Resolution: ...
3333
def ints_to_pydatetime(
34-
arr: npt.NDArray[np.int64],
34+
stamps: npt.NDArray[np.int64],
3535
tz: tzinfo | None = ...,
3636
box: str = ...,
3737
reso: int = ..., # NPY_DATETIMEUNIT

pandas/_libs/window/aggregations.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def ewm(
111111
com: float, # float64_t
112112
adjust: bool,
113113
ignore_na: bool,
114-
deltas: np.ndarray, # const float64_t[:]
115-
normalize: bool,
114+
deltas: np.ndarray | None = None, # const float64_t[:]
115+
normalize: bool = True,
116116
) -> np.ndarray: ... # np.ndarray[np.float64]
117117
def ewmcov(
118118
input_x: np.ndarray, # const float64_t[:]

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,8 +2314,7 @@ def _concat_same_type(
23142314
return new_obj
23152315

23162316
def copy(self, order: str = "C") -> Self:
2317-
# error: Unexpected keyword argument "order" for "copy"
2318-
new_obj = super().copy(order=order) # type: ignore[call-arg]
2317+
new_obj = super().copy(order=order)
23192318
new_obj._freq = self.freq
23202319
return new_obj
23212320

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ requires = [
55
"meson-python==0.13.1",
66
"meson==1.2.1",
77
"wheel",
8-
"Cython>=0.29.33,<3", # Note: sync with setup.py, environment.yml and asv.conf.json
8+
"Cython==3.0.5", # Note: sync with setup.py, environment.yml and asv.conf.json
99
# Any NumPy version should be fine for compiling. Users are unlikely
1010
# to get a NumPy<1.25 so the result will be compatible with all relevant
1111
# NumPy versions (if not it is presumably compatible with their version).

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
pip
55
versioneer[toml]
6-
cython==0.29.33
6+
cython==3.0.5
77
meson[ninja]==1.2.1
88
meson-python==0.13.1
99
pytest>=7.3.2

scripts/run_stubtest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
# stubtest might be too sensitive
4848
"pandas._libs.lib.NoDefault",
4949
"pandas._libs.lib._NoDefault.no_default",
50+
# stubtest/Cython is not recognizing the default value for the dtype parameter
51+
"pandas._libs.lib.map_infer_mask",
5052
# internal type alias (should probably be private)
5153
"pandas._libs.lib.ndarray_obj_2d",
5254
# runtime argument "owner" has a default value but stub argument does not

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def is_platform_mac():
3737

3838

3939
# note: sync with pyproject.toml, environment.yml and asv.conf.json
40-
min_cython_ver = "0.29.33"
40+
min_cython_ver = "3.0.5"
4141

4242
try:
4343
from Cython import (

0 commit comments

Comments
 (0)