Skip to content

scipy/ppf-of-complement

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

ppf(1 - p) rounds away the digits of a small p, so it loses precision far in the tail. Call isf(p).

crit = stats.norm.ppf(1 - alpha / 2)
crit = stats.norm.isf(alpha / 2)

The rule reports dist.ppf(1 - p, ...) and dist.isf(1 - p, ...) for a continuous scipy.stats distribution from a measured list, and special.ndtri(1 - p). The old form lost 3 or more digits for every p below 5e-7. A probability written as a number, such as 1 - 0.05, is left alone unless it is below 5e-7.

f is left out of the inverse-survival rewrite because its isf also lost accuracy in the measured tail. The reverse rewrite leaves out pareto for the same reason with its ppf. Discrete distributions are left out because their two inverse methods can break ties differently.

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.isf(p, ...), dist.ppf(p, ...), -special.ndtri(p).

The replacement can change the last bits.

1 - $P rounds away the digits of a small $P, so this lost at least 3 digits for $P below 5e-7 and gives the end of the support below 1.1e-16, where $R.isf lost less than 1. Write $R.isf($REST).

See all rules in the SciPy pack.