Skip to content

Commit 34eb701

Browse files
committed
Clip covxy / divsor instead of result
1 parent 7f2fdaa commit 34eb701

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

pandas/_libs/algos.pyx

+3-4
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,13 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None):
389389
else:
390390
divisor = (nobs - 1.0) if cov else sqrt(ssqdmx * ssqdmy)
391391

392+
# clip `covxy / divisor` to ensure coeff is within bounds
392393
if divisor != 0:
393-
result[xi, yi] = result[yi, xi] = covxy / divisor
394+
val = np.clip(covxy / divisor, -1, 1)
395+
result[xi, yi] = result[yi, xi] = val
394396
else:
395397
result[xi, yi] = result[yi, xi] = NaN
396398

397-
# clip coefficient to ensure it is within theoretical bounds
398-
result = np.clip(result, -1, 1)
399-
400399
return result.base
401400

402401
# ----------------------------------------------------------------------

0 commit comments

Comments
 (0)