Skip to content

CLN: nancorr cleanups #42757

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 1 commit into from
Jul 28, 2021
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
21 changes: 10 additions & 11 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,10 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
cdef:
Py_ssize_t i, j, xi, yi, N, K
bint minpv
ndarray[float64_t, ndim=2] result
float64_t[:, ::1] result
ndarray[uint8_t, ndim=2] mask
int64_t nobs = 0
float64_t vx, vy, meanx, meany, divisor, prev_meany, prev_meanx, ssqdmx
float64_t ssqdmy, covxy
float64_t vx, vy, dx, dy, meanx, meany, divisor, ssqdmx, ssqdmy, covxy

N, K = (<object>mat).shape

Expand All @@ -352,13 +351,13 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
vx = mat[i, xi]
vy = mat[i, yi]
nobs += 1
prev_meanx = meanx
prev_meany = meany
meanx = meanx + 1 / nobs * (vx - meanx)
meany = meany + 1 / nobs * (vy - meany)
ssqdmx = ssqdmx + (vx - meanx) * (vx - prev_meanx)
ssqdmy = ssqdmy + (vy - meany) * (vy - prev_meany)
covxy = covxy + (vx - meanx) * (vy - prev_meany)
dx = vx - meanx
dy = vy - meany
meanx += 1 / nobs * dx
meany += 1 / nobs * dy
ssqdmx += (vx - meanx) * dx
ssqdmy += (vy - meany) * dy
covxy += (vx - meanx) * dy

if nobs < minpv:
result[xi, yi] = result[yi, xi] = NaN
Expand All @@ -370,7 +369,7 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
else:
result[xi, yi] = result[yi, xi] = NaN

return result
return result.base

# ----------------------------------------------------------------------
# Pairwise Spearman correlation
Expand Down