numpy/percentile-of-fraction
| Rule | percentile-of-fraction |
|---|---|
| Pack | NumPy |
| Severity | warning |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
np.percentile takes percents from 0 to 100, so 0.95 asks for a value near the minimum. Use np.quantile for fractions, or pass 95.
upper = np.percentile(x, 0.95)upper = np.quantile(x, 0.95)What the rule reports
Section titled “What the rule reports”The rule reports np.percentile(x, 0.95) and np.percentile(x, [0.25, 0.75]). np.percentile takes percents from 0 to 100, so both calls ask for values near the minimum.
The rule leaves a list such as [0.5, 99.5] alone, where one number is a percent.
How to fix it
Section titled “How to fix it”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 np.quantile(x, 0.95).
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
$NP.$F takes percents from 0 to 100, so $Q asks for a percentile near the minimum. For fractions write $NP.$G($A, $Q).Browse the other rules of the NumPy pack.