GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — BUG: Fix np.quantile([0, 1], 0, method='weibull') by eendebakpt · Pull Request #24710 · numpy/numpy Conversation
|
| supports_integers = supports_integers or \ | ||
| (method == 'linear' and int_virtual_indices) | ||
|
|
||
| if supports_integers: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I have to think about it a tiny bit more maybe. We end up with integers here due to integer input. I suspect we had discussed this, but I am not sure we got it right: I wonder if we shouldn't just use method_props["fix_gamma"] is None.
That would change the odd exception method == 'linear' with 0 or 1 as input. But I rather prefer the clarity that the result type depends (mainly) on the method and not on some (very special!) values.
(Others may have disagreed though, arguing that for 0 and 1 the answer is clearly exact for the linear method.)
I like the fix_gamma to None refactor, though. And I am not convinced that a / 1 to the virtual index calculation (or so... which would also be plausible) would be a better fix.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The type indeed depends on the input values: np.quantile([0,1,2,3,],[0,1]) results in integer type, while np.quantile([0,1,2,3,],[0,.1]) is float.
The reason for making an exception for method == 'linear' is to allow for tf_quant = np.quantile(True, False). That case is in the unit tests, so I added the special case to keep supporting it.
It seems very odd to run quantile on boolean types though....
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah, I still agree with my above comment: linear interpolation should always interpolate to ensure the right result dtype, IMO. Even if the user passed in 0 or 1 to the quantile.
(Assuming this is what is going on, because I didn't think about it very long now.)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@seberg Always interpolating for method 'linear' indeed seems the right thing to do. I do not expect any performance loss in the general case (where the quantiles argument will have floating values and not just 0 and 1). On the other hand:
float64, but might for other input typesnp.quantile([1,2,1,2,1,2], [0, 1]) results in array([1, 2]) (so integer type), while np.quantile([1,2,1,2,1,2], [0.5]) results in array([1.5]) (floating type). So always running the interpolation is no guarantee we end up with the same dtype (even for the same dtype input). For the linear method this could be solved by replacing 1 with 1. somewhere in the code. But again: that works fine for the normal input types (float32, float64), but might change behavior for other types.np.quantile([True], [False]) fails because TypeError: numpy boolean subtract, the - operator is not supported, use .... How to deal with this? We could just drop support for any input types that do not support subtract (for the linear method). Another option would be to decide whether to take the integer path based on the input dtype. So dtype=boolean: use the integer path, dtype=float64: do not use the input path. The latter option does not seem very elegant though, I would not want to have a big table deciding how to handle different input dtypes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This error is raised because you're trying to calculate the 100% quantile (q=1) on an array of size 10. However, this results in a problem when the method tries to find the "10th" element in an array that only has indices 0-9. np.quantile(x, 1.0, method='weibull') #use1.0 instead of 1 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Your observation is correct, with value |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if np.issubdtype(virtual_indexes.dtype, np.integer): | ||
| int_virtual_indices = np.issubdtype(virtual_indexes.dtype, np.integer) | ||
| supports_integers = method_props["fix_gamma"] is None | ||
| supports_integers = supports_integers or \ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This PR needs a rebase unfortunately. Just commenting here to nitpick that I would prefer no \ continuation :).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Did a rebase (with force push). The \ was there to avoid a line too long, I rewrote the style to make it fit.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the other solution (with the exception of with statements) is to just use parantheses (...) which allow spanning multiple lines :).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| virtual_indexes = np.asanyarray(virtual_indexes) | ||
|
|
||
| if np.issubdtype(virtual_indexes.dtype, np.integer): | ||
| int_virtual_indices = np.issubdtype(virtual_indexes.dtype, np.integer) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| int_virtual_indices = np.issubdtype(virtual_indexes.dtype, np.integer) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought you didn't use it at all?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
close/reopen |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks, FWIW, I still don't like the special case, and I would probably prefer to just change the test and disallow act is if q was a raction (i.e. you could say as if |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
BUG: quantile 1 with 'weibull' gives confusing error
There was an error while loading. Please reload this page.