Skip to content

Commit 835b280

Browse files
authored
CLN: tighten cython declarations (#40834)
1 parent 7d4757b commit 835b280

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

pandas/_libs/index.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ cdef class IndexEngine:
7474
return val in self.mapping
7575

7676
cpdef get_loc(self, object val):
77+
# -> Py_ssize_t | slice | ndarray[bool]
7778
cdef:
7879
Py_ssize_t loc
7980

@@ -109,6 +110,7 @@ cdef class IndexEngine:
109110
raise KeyError(val)
110111

111112
cdef inline _get_loc_duplicates(self, object val):
113+
# -> Py_ssize_t | slice | ndarray[bool]
112114
cdef:
113115
Py_ssize_t diff
114116

@@ -142,6 +144,7 @@ cdef class IndexEngine:
142144
cdef _unpack_bool_indexer(self,
143145
ndarray[uint8_t, ndim=1, cast=True] indexer,
144146
object val):
147+
# Returns ndarray[bool] or int
145148
cdef:
146149
ndarray[intp_t, ndim=1] found
147150
int count

pandas/_libs/index_class_helper.pxi.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ cdef class {{name}}Engine(IndexEngine):
4444
raise KeyError(val)
4545
{{endif}}
4646

47-
cdef void _call_map_locations(self, ndarray values):
48-
self.mapping.map_locations(algos.ensure_{{name.lower()}}(values))
47+
cdef void _call_map_locations(self, ndarray[{{dtype}}_t] values):
48+
self.mapping.map_locations(values)
4949

5050
cdef _maybe_get_bool_indexer(self, object val):
5151
# Returns ndarray[bool] or int

pandas/_libs/intervaltree.pxi.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ cdef class IntervalTree(IntervalMixin):
7373
self.root = node_cls(self.left, self.right, indices, leaf_size)
7474

7575
@property
76-
def left_sorter(self):
76+
def left_sorter(self) -> np.ndarray:
7777
"""How to sort the left labels; this is used for binary search
7878
"""
7979
if self._left_sorter is None:
8080
self._left_sorter = np.argsort(self.left)
8181
return self._left_sorter
8282

8383
@property
84-
def right_sorter(self):
84+
def right_sorter(self) -> np.ndarray:
8585
"""How to sort the right labels
8686
"""
8787
if self._right_sorter is None:
8888
self._right_sorter = np.argsort(self.right)
8989
return self._right_sorter
9090

9191
@property
92-
def is_overlapping(self):
92+
def is_overlapping(self) -> bool:
9393
"""
9494
Determine if the IntervalTree contains overlapping intervals.
9595
Cached as self._is_overlapping.
@@ -109,7 +109,7 @@ cdef class IntervalTree(IntervalMixin):
109109
return self._is_overlapping
110110

111111
@property
112-
def is_monotonic_increasing(self):
112+
def is_monotonic_increasing(self) -> bool:
113113
"""
114114
Return True if the IntervalTree is monotonic increasing (only equal or
115115
increasing values), else False
@@ -119,7 +119,7 @@ cdef class IntervalTree(IntervalMixin):
119119
sort_order = np.lexsort(values)
120120
return is_monotonic(sort_order, False)[0]
121121

122-
def get_indexer(self, scalar_t[:] target):
122+
def get_indexer(self, scalar_t[:] target) -> np.ndarray:
123123
"""Return the positions corresponding to unique intervals that overlap
124124
with the given array of scalar targets.
125125
"""
@@ -180,7 +180,7 @@ cdef class IntervalTree(IntervalMixin):
180180
n_elements=self.root.n_elements))
181181

182182
# compat with IndexEngine interface
183-
def clear_mapping(self):
183+
def clear_mapping(self) -> None:
184184
pass
185185

186186

pandas/_libs/sparse.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ cdef class BlockIndex(SparseIndex):
618618
pass
619619

620620

621+
@cython.internal
621622
cdef class BlockMerge:
622623
"""
623624
Object-oriented approach makes sharing state between recursive functions a
@@ -661,6 +662,7 @@ cdef class BlockMerge:
661662
self.yi = xi
662663

663664

665+
@cython.internal
664666
cdef class BlockUnion(BlockMerge):
665667
"""
666668
Object-oriented approach makes sharing state between recursive functions a

pandas/_libs/tslibs/conversion.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, tzinfo tz,
2828

2929
cdef int64_t get_datetime64_nanos(object val) except? -1
3030

31-
cpdef datetime localize_pydatetime(datetime dt, object tz)
31+
cpdef datetime localize_pydatetime(datetime dt, tzinfo tz)
3232
cdef int64_t cast_from_unit(object ts, str unit) except? -1
3333
cpdef (int64_t, int) precision_from_unit(str unit)
3434

pandas/_libs/tslibs/conversion.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,14 @@ cdef inline datetime _localize_pydatetime(datetime dt, tzinfo tz):
810810
return dt.replace(tzinfo=tz)
811811

812812

813-
cpdef inline datetime localize_pydatetime(datetime dt, object tz):
813+
cpdef inline datetime localize_pydatetime(datetime dt, tzinfo tz):
814814
"""
815815
Take a datetime/Timestamp in UTC and localizes to timezone tz.
816816
817817
Parameters
818818
----------
819819
dt : datetime or Timestamp
820-
tz : tzinfo, "UTC", or None
820+
tz : tzinfo or None
821821
822822
Returns
823823
-------

0 commit comments

Comments
 (0)