Skip to content

Commit fc5ccae

Browse files
committed
Clip covxy / divsor within nogil
1 parent 34eb701 commit fc5ccae

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/_libs/algos.pyx

+6-3
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,9 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
353353
float64_t[:, ::1] result
354354
uint8_t[:, :] mask
355355
int64_t nobs = 0
356-
float64_t vx, vy, dx, dy, meanx, meany, divisor, ssqdmx, ssqdmy, covxy
356+
float64_t vx, vy, dx, dy, meanx, meany, divisor, ssqdmx, ssqdmy, covxy, val
357357

358358
N, K = (<object>mat).shape
359-
360359
if minp is None:
361360
minpv = 1
362361
else:
@@ -391,7 +390,11 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
391390

392391
# clip `covxy / divisor` to ensure coeff is within bounds
393392
if divisor != 0:
394-
val = np.clip(covxy / divisor, -1, 1)
393+
val = covxy / divisor
394+
if val > 1.0:
395+
val = 1.0
396+
elif val < -1.0:
397+
val = -1.0
395398
result[xi, yi] = result[yi, xi] = val
396399
else:
397400
result[xi, yi] = result[yi, xi] = NaN

0 commit comments

Comments
 (0)