Skip to content

CLN: Added static types _libs/algos #33271

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 4 commits into from
Apr 5, 2020
Merged
Changes from all commits
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
39 changes: 15 additions & 24 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ from pandas._libs.khash cimport (

import pandas._libs.missing as missing

cdef float64_t FP_ERR = 1e-13

cdef float64_t NaN = <float64_t>np.NaN

cdef int64_t NPY_NAT = get_nat()
cdef:
float64_t FP_ERR = 1e-13
float64_t NaN = <float64_t>np.NaN
int64_t NPY_NAT = get_nat()

tiebreakers = {
'average': TIEBREAK_AVERAGE,
'min': TIEBREAK_MIN,
'max': TIEBREAK_MAX,
'first': TIEBREAK_FIRST,
'dense': TIEBREAK_DENSE,
"average": TIEBREAK_AVERAGE,
"min": TIEBREAK_MIN,
"max": TIEBREAK_MAX,
"first": TIEBREAK_FIRST,
"dense": TIEBREAK_DENSE,
}


Expand Down Expand Up @@ -120,6 +119,7 @@ cpdef ndarray[int64_t, ndim=1] unique_deltas(const int64_t[:] arr):
kh_int64_t *table
int ret = 0
list uniques = []
ndarray[int64_t, ndim=1] result

table = kh_init_int64()
kh_resize_int64(table, 10)
Expand Down Expand Up @@ -261,7 +261,7 @@ def kth_smallest(numeric[:] a, Py_ssize_t k) -> numeric:

@cython.boundscheck(False)
@cython.wraparound(False)
def nancorr(const float64_t[:, :] mat, bint cov=0, minp=None):
def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated C code for this was not changed

cdef:
Py_ssize_t i, j, xi, yi, N, K
bint minpv
Expand Down Expand Up @@ -325,7 +325,7 @@ def nancorr(const float64_t[:, :] mat, bint cov=0, minp=None):

@cython.boundscheck(False)
@cython.wraparound(False)
def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1):
def nancorr_spearman(const float64_t[:, :] mat, Py_ssize_t minp=1) -> ndarray:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does adding these return annotations to the def like this change anything?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for functions that arent cdef/cpdef its ornamental

cdef:
Py_ssize_t i, j, xi, yi, N, K
ndarray[float64_t, ndim=2] result
Expand Down Expand Up @@ -581,7 +581,7 @@ D

@cython.boundscheck(False)
@cython.wraparound(False)
def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None):
def backfill(ndarray[algos_t] old, ndarray[algos_t] new, limit=None) -> ndarray:
cdef:
Py_ssize_t i, j, nleft, nright
ndarray[int64_t, ndim=1] indexer
Expand Down Expand Up @@ -810,18 +810,14 @@ def rank_1d(
"""
cdef:
Py_ssize_t i, j, n, dups = 0, total_tie_count = 0, non_na_idx = 0

ndarray[rank_t] sorted_data, values

ndarray[float64_t] ranks
ndarray[int64_t] argsorted
ndarray[uint8_t, cast=True] sorted_mask

rank_t val, nan_value

float64_t sum_ranks = 0
int tiebreak = 0
bint keep_na = 0
bint keep_na = False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated C code for this was not changed

bint isnan, condition
float64_t count = 0.0

Expand Down Expand Up @@ -1034,19 +1030,14 @@ def rank_2d(
"""
cdef:
Py_ssize_t i, j, z, k, n, dups = 0, total_tie_count = 0

Py_ssize_t infs

ndarray[float64_t, ndim=2] ranks
ndarray[rank_t, ndim=2] values

ndarray[int64_t, ndim=2] argsorted

rank_t val, nan_value

float64_t sum_ranks = 0
int tiebreak = 0
bint keep_na = 0
bint keep_na = False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated C code for this was not changed

float64_t count = 0.0
bint condition, skip_condition

Expand Down