Skip to content

scipy/cdf-complement

Pack Severity Fix Versions
SciPy warning unsafe, with xpd check --fix --unsafe-fixes All versions

1 - dist.cdf(x) drops the digits of a small right tail and gives 0 once the cdf rounds to 1. Call dist.sf(x), which keeps them.

pvalue = 2 * (1 - stats.norm.cdf(np.abs(z)))
pvalue = 2 * stats.norm.sf(np.abs(z))

The rule reports 1 - dist.cdf(...) and 1 - dist.sf(...) for a scipy.stats distribution from a measured list. For stats.norm, 1 - cdf lost 3 or more digits above 4.25 and gave 0 above 8.3. lognorm, f, poisson, binom, nbinom and geom are not on the list, because their sf lost digits too.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes dist.sf(...), dist.cdf(...).

The replacement can change the last bits. A distribution subclass can implement sf independently of 1 - cdf.

Subtracting $R.cdf from 1 drops the digits of a small right tail and gives 0 once the cdf rounds to 1. In the runs that lost up to all 16 digits, and $R.sf was never a digit worse. Write $R.sf($$$A).

See all rules in the SciPy pack.