You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When one or more inf or -inf are present in the argument to np.quantile (or np.nanquantile), the results often include nan, when +/-inf could be reasonably returned -- e.g. if there are 10 -infs in 100-long x, np.quantile(x,.05) should probably return -inf, not nan.
np.quantile(-inf,0) =/= np.quantile(-inf,0.) (int vs float, and similarly for 1 vs 1.)
The behaviour for -inf and inf is possibly different in some situations -- e.g. compare actual outputs 7 vs 9 below: the median in 7 that averages 2 and inf returns nan while the median in 9 that averages -inf and 3 returns -inf.
The reason NaN is returned so often is because quantile() runs interpolation calculations on the input array, which results in running custom addition, subtraction, and multiplication functions on infinite values, which they don't know how to handle (this is what all the errors are referring to).
The reason np.quantile(-inf,0) =/= np.quantile(-inf,0.) is because the interpolation calculations are not run if the input quantile is an integer (this check is in numpy/lib/function_base.py line 4651). This means that there is no instance where the code is running infinite value arithmetic if an integer quantile is passed in.
Still looking into how 7 and 9 get different outputs.
I'm trying to code a solution to this issue, but it's looking a lot more difficult than I thought it would be, because I can't (and probably shouldn't) manipulate the add/subtract/multiply functions that cause the issue, which means I have to create a manual workaround. I have an if statement that checks if the input contains inf or -inf, and if not, it runs the original interpolation calculations, which should prevent my workaround from breaking old code or introducing new bugs. However, my workaround is really janky, because I don't know how to generalize inputs of different types (since the input can be array-like, which means the inputs can be arrays, lists, single values, etc.) and because I have to manually loop through the input to detect infinite values.
I'm probably gonna submit a pull request soon so people can look at my code and, if possible, provide some insight, as I'm fairly new to this. As it stands, my workaround somewhat works, but I feel like there has to be a more efficient and clean way to do this. My changes are all in _lerp(), line 4485.
Describe the issue:
When one or more
inf
or-inf
are present in the argument tonp.quantile
(ornp.nanquantile
), the results often includenan
, when+/-inf
could be reasonably returned -- e.g. if there are 10-inf
s in 100-longx
,np.quantile(x,.05)
should probably return-inf
, notnan
.np.quantile(-inf,0)
=/=np.quantile(-inf,0.)
(int vs float, and similarly for1
vs1.
)The behaviour for
-inf
andinf
is possibly different in some situations -- e.g. compare actual outputs 7 vs 9 below: the median in 7 that averages 2 andinf
returnsnan
while the median in 9 that averages-inf
and 3 returns-inf
.Likely related: #12282
Reproduce the code example:
Error message:
NumPy/Python version information:
1.22.2 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0]
The text was updated successfully, but these errors were encountered: