From 337ad8e87e41692b094d361ac427261ea34dcbd9 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Mon, 27 Jun 2022 16:05:44 +0200 Subject: [PATCH 1/2] PERF: use c-division in nancorr --- pandas/_libs/algos.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 29f9a22c9b36e..9203e60d857a7 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -324,6 +324,7 @@ def kth_smallest(numeric_t[::1] arr, Py_ssize_t k) -> numeric_t: @cython.boundscheck(False) @cython.wraparound(False) +@cython.cdivision(True) def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None): cdef: Py_ssize_t i, j, xi, yi, N, K From 77cbc60c7206f4ff34e450df19bba38b262a0ebc Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Mon, 27 Jun 2022 21:42:36 +0200 Subject: [PATCH 2/2] make numerator in division float --- pandas/_libs/algos.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/algos.pyx b/pandas/_libs/algos.pyx index 9203e60d857a7..c05d6a300ccf0 100644 --- a/pandas/_libs/algos.pyx +++ b/pandas/_libs/algos.pyx @@ -357,8 +357,8 @@ def nancorr(const float64_t[:, :] mat, bint cov=False, minp=None): nobs += 1 dx = vx - meanx dy = vy - meany - meanx += 1 / nobs * dx - meany += 1 / nobs * dy + meanx += 1. / nobs * dx + meany += 1. / nobs * dy ssqdmx += (vx - meanx) * dx ssqdmy += (vy - meany) * dy covxy += (vx - meanx) * dy