I added np.clip to pg.corr, right after where all the r values are calculated and before being passed to power_corr, so I think this should catch all similar cases. Rather than always clipping, I only do it if the r value exceeds -1 or 1 andnp.isclose to abs(1). I don't imagine getting r values exceeding those bounds, but this felt safer to prevent accidentally clipping something super-high down to 1.
Re-running the original code that produced the error will work now:
import numpy as np
import pingouin as pg
pg.corr([1, np.nan, 2, 4], [1, 2, np.nan, 3], method='bicor')
# bicor 2 1.0 [1.0, 1.0] NaN 1
Fixes #340
I added
np.clip
topg.corr
, right after where all ther
values are calculated and before being passed topower_corr
, so I think this should catch all similar cases. Rather than always clipping, I only do it if the r value exceeds -1 or 1 andnp.isclose
to abs(1). I don't imagine getting r values exceeding those bounds, but this felt safer to prevent accidentally clipping something super-high down to 1.Re-running the original code that produced the error will work now: