Closed chunweiyuan closed 4 months ago
I'm sure this is useful, but we try to avoid putting new numeric methods in xarray itself. Would the underlying weighted quantile method (on NumPy arrays) be appropriate for numpy or scipy? Then we might consider adding a wrapper function in xarray (though again, we have to be cautious to avoid overloading xarray with too many methods).
Cool, let me toss it out on the numpy board and see what they think.
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity
If this issue remains relevant, please comment here or remove the stale
label; otherwise it will be marked as closed automatically
We could also add things like this to a cookbook section in the docs
So, as per suggestion by Stephan, I submitted the PR to numpy instead: https://github.com/numpy/numpy/pull/9211
Despite having possibly the highest number of comments of all active numpy PRs and passing all the tests, it's been sitting in limbo for the last few months. There seems to be quite some uncertainty about what to do with it, and the discussion has gone off tangent a bit to more upstream issues.
My hope is still to have it eventually merged into numpy, so that it could be easily ported to xarray. It's proven to be quite useful to my coworkers, as well as some of the numpy users. I believe it'll also serve xarray well. Thank you all for your patience.
Would you like to leave this open @chunweiyuan ?
That's quite a thread! I'm impressed by your persistence
My personal hope is to keep this thread open just for the record. But given the non-activity on the numpy end, I honestly can't promise any resolution to this issue in the near future. Thanks!
PS I persist because some people do seem to appreciate that PR and have forked it for their own use :)
NumPy does have a pretty bad review back-log :(
On Fri, Mar 15, 2019 at 11:01 AM chunweiyuan notifications@github.com wrote:
My personal hope is to keep this thread open just for the record. But given the non-activity on the numpy end, I honestly can't promise any resolution to this issue in the near future. Thanks!
PS I persist because some people do seem to appreciate that PR and have forked it for their own use :)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pydata/xarray/issues/1371#issuecomment-473387146, or mute the thread https://github.com/notifications/unsubscribe-auth/ABKS1gzAFmpKOTSi0ljefC46A79vp8m1ks5vW9_8gaJpZM4M73c4 .
Closing as stale but please reopen if sufficiently pressing.
FYI there are quantile routines in numbagg — I'd be happy to accept a PR adding a weights arg to that....
For our work we frequently need to compute weighted quantiles. This is especially important when we need to weigh data from recent years more heavily in making predictions.
I've put together a function (called
weighted_quantile
) largely based on the source code ofnp.percentile
. It allows one to input weights along a single dimension, as a dictw_dict
. Below are some manual tests:When all weights = 1, it's identical to using
np.nanpercentile
:Now different weights:
Also handles nan values like
np.nanpercentile
:Lastly, different interpolation schemes are consistent:
We wonder if it's ok to make this part of xarray. If so, the most logical place to implement it would seem to be in
Variable.quantile()
. Another option is to make it a utility function, to be called asxr.weighted_quantile()
.