Skip to content

Commit 213822a

Browse files
authored
CLN: Added static types _libs/algos (#33271)
1 parent a9b051c commit 213822a

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

pandas/_libs/algos.pyx

+15-24
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ from pandas._libs.khash cimport (
5050

5151
import pandas._libs.missing as missing
5252

53-
cdef float64_t FP_ERR = 1e-13
54-
55-
cdef float64_t NaN = <float64_t>np.NaN
56-
57-
cdef int64_t NPY_NAT = get_nat()
53+
cdef:
54+
float64_t FP_ERR = 1e-13
55+
float64_t NaN = <float64_t>np.NaN
56+
int64_t NPY_NAT = get_nat()
5857

5958
tiebreakers = {
60-
'average': TIEBREAK_AVERAGE,
61-
'min': TIEBREAK_MIN,
62-
'max': TIEBREAK_MAX,
63-
'first': TIEBREAK_FIRST,
64-
'dense': TIEBREAK_DENSE,
59+
"average": TIEBREAK_AVERAGE,
60+
"min": TIEBREAK_MIN,
61+
"max": TIEBREAK_MAX,
62+
"first": TIEBREAK_FIRST,
63+
"dense": TIEBREAK_DENSE,
6564
}
6665

6766

@@ -120,6 +119,7 @@ cpdef ndarray[int64_t, ndim=1] unique_deltas(const int64_t[:] arr):
120119
kh_int64_t *table
121120
int ret = 0
122121
list uniques = []
122+
ndarray[int64_t, ndim=1] result
123123

124124
table = kh_init_int64()
125125
kh_resize_int64(table, 10)
@@ -261,7 +261,7 @@ def kth_smallest(numeric[:] a, Py_ssize_t k) -> numeric:
261261

262262
@cython.boundscheck(False)
263263
@cython.wraparound(False)
264-
def nancorr(const float64_t[:, :] mat, bint cov=0, minp=None):
264+
def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
265265
cdef:
266266
Py_ssize_t i, j, xi, yi, N, K
267267
bint minpv
@@ -325,7 +325,7 @@ def nancorr(const float64_t[:, :] mat, bint cov=0, minp=None):
325325

326326
@cython.boundscheck(False)
327327
@cython.wraparound(False)
328-
def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
328+
def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1) -> ndarray:
329329
cdef:
330330
Py_ssize_t i, j, xi, yi, N, K
331331
ndarray[float64_t, ndim=2] result
@@ -581,7 +581,7 @@ D
581581

582582
@cython.boundscheck(False)
583583
@cython.wraparound(False)
584-
def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
584+
def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None) -> ndarray:
585585
cdef:
586586
Py_ssize_t i, j, nleft, nright
587587
ndarray[int64_t, ndim=1] indexer
@@ -810,18 +810,14 @@ def rank_1d(
810810
"""
811811
cdef:
812812
Py_ssize_t i, j, n, dups = 0, total_tie_count = 0, non_na_idx = 0
813-
814813
ndarray[rank_t] sorted_data, values
815-
816814
ndarray[float64_t] ranks
817815
ndarray[int64_t] argsorted
818816
ndarray[uint8_t, cast=True] sorted_mask
819-
820817
rank_t val, nan_value
821-
822818
float64_t sum_ranks = 0
823819
int tiebreak = 0
824-
bint keep_na = 0
820+
bint keep_na = False
825821
bint isnan, condition
826822
float64_t count = 0.0
827823

@@ -1034,19 +1030,14 @@ def rank_2d(
10341030
"""
10351031
cdef:
10361032
Py_ssize_t i, j, z, k, n, dups = 0, total_tie_count = 0
1037-
10381033
Py_ssize_t infs
1039-
10401034
ndarray[float64_t, ndim=2] ranks
10411035
ndarray[rank_t, ndim=2] values
1042-
10431036
ndarray[int64_t, ndim=2] argsorted
1044-
10451037
rank_t val, nan_value
1046-
10471038
float64_t sum_ranks = 0
10481039
int tiebreak = 0
1049-
bint keep_na = 0
1040+
bint keep_na = False
10501041
float64_t count = 0.0
10511042
bint condition, skip_condition
10521043

0 commit comments

Comments
 (0)