-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: quantile 1 with 'weibull' gives confusing error #24592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicki 8000 ng “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem is you are passing 1 as an integer argument, while the documentation states For input zero however, the results are:
The fact that we get an incorrect answer when passing |
There are a couple more cases affected:
Output:
Two simple solutions:
The problems arise in this code path: https://github.com/numpy/numpy/blob/main/numpy/lib/_function_base_impl.py#L4731. I suspect the special code path for integers is there for performance reasons. |
Is there any reason not to convert to float? I mean - what is the advantage of the error? |
Such a change would be backwards incompatible. For example:
Not sure whether the numpy/numpy/lib/tests/test_function_base.py Line 3582 in da8cdcf
Adding @eric-wieser as the author of the tests in the CC. |
Sorry @eendebakpt - just checking - you mean automatic conversion to float would be backwards incompatible? Surely the current behavior can't be intentional, of failing with a floating point 0 (but not integer 0) for a fraction value? What would the purpose of such a failure be? |
Yes, the automatic conversion would break one of the tests I linked to, so it would be backwards incompatible. I do agree that the current behavior is strange, and perhaps something we can change. But that is up to a numpy core developer. |
Just checking - but the point here is that e.g. |
I am interested tosolve this can you please assign me this issue |
@Anianonymous There already is a PRs to fix this issue: #24710. You can help to review the PR. |
Issue #24592 was opened because the np.quantile method gives incorrect answers for the weibull method. The problem: import numpy as np x=np.arange(10) np.quantile(x, 0., method='weibull') # output 0.0, correct np.quantile(x, 0, method='weibull') # output 9, incorrect! np.quantile(x, 1, method='weibull') # raises an error The value of np.quantile(x, q=0, method='weibull') is incorrect for integer inputs. Two options to address this: Do not allow integer input for np.quantile. The documentation for the probability argument states that "q : array_like of float", so this seems reasonable. But this would be a behaviour change that might have a large impact and there are unit tests that test for integer input as well. Automatically cast the input argument q to float. Also this would be a behaviour change and break existing tests. We rejected these two options because of the issues mentioned. Applying either one of the options only for weibull would make the input handling less uniform. The problem with weibull (and some other methods) is that inside np.lib._function_base_impl._quantile there are two paths: one for integer virtual indices and one for other types of virtual indices (in the code the statement if np.issubdtype(virtual_indexes.dtype, np.integer):. The integer path is only valid for methods returning integer indices in the range [0, size(arr)>. For the weibull method something like q = [0, .5, 1] is cast to float, which results in float virtual_indices (which contains floats with integer values, but that is okay). We can either: i) Modify the code in the integer path to handle integers < 0 and > size(arr) -1 ii) Check whether the methods supports integer output, and if not use the alternative path We opted for the second option. Fixes #24592
Describe the issue:
Asking for the 1 quantile with
weibull
gives a confusing error - see below.Reproduce the code example:
Error message:
[1] import sys, numpy; print(numpy.version); print(sys.version)
1.26.0b1
3.10.11 (main, Apr 7 2023, 07:24:53) [Clang 14.0.0 (clang-1400.0.29.202)]
In [2]: print(numpy.show_runtime())
WARNING:
threadpoolctl
not found in system! Install it bypip install threadpoolctl
. Once installed, trynp.show_runtime
again for more detailed build information[{'numpy_version': '1.26.0b1',
'python': '3.10.11 (main, Apr 7 2023, 07:24:53) [Clang 14.0.0 '
'(clang-1400.0.29.202)]',
'uname': uname_result(system='Darwin', node='nipraxis.dynevor.org', release='22.6.0', version='Darwin Kernel Version 22.6.0: Wed Jul 5 22:17:35 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8112', machine='arm64')},
{'simd_extensions': {'baseline': ['NEON', 'NEON_FP16', 'NEON_VFPV4', 'ASIMD'],
'found': ['ASIMDHP'],
'not_found': ['ASIMDFHM']}}]
The text was updated successfully, but these errors were encountered: