-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 clicking “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
Change .groupby fastpath to work for monotonic increasing and decreasing #7427
Change .groupby fastpath to work for monotonic increasing and decreasing #7427
Conversation
This fixes GH6220 which makes it possible to use the fast path for .groupby for monotonically increasing and decreasing values.
Thanks @JoelJaeschke! The intent was to change the code in A good test would be make sure you get the same answer when grouping a DataArray of ones by a monotonically increasing variable (e.g. |
…ath-when-grouping-unique-monotonic-variable
Hi @dcherian I am not sure if I understand correctly what you are saying, but if I implement the test as you describe, would this not already work anyways? It will take the slow-path, but the behavior should be identical, right? My intention when writing the test was to explicitly test this case by supplying a grouper. |
TO check the fastpath we'd want to both get the right answer and make sure that Lines 422 to 430 in 4f3128b
|
…ath-when-grouping-unique-monotonic-variable
c8efb23
to
f4bb524
Compare
0022c13
to
38ff104
Compare
…monotonic-variable
Hi @dcherian, I implemented the feedback as you described, hope this does the trick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JoelJaeschke Can you add a line to doc/whats-new.rst
please?
xarray/core/groupby.py
Outdated
@@ -400,7 +402,9 @@ def __init__( | |||
index = safe_cast_to_index(group) | |||
if not index.is_monotonic_increasing: | |||
# TODO: sort instead of raising an error | |||
raise ValueError("index must be monotonic for resampling") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I undid this change. It's more involved to make it actually work.
fwd = array.groupby("idx", squeeze=False) | ||
rev = array_rev.groupby("idx", squeeze=False) | ||
|
||
for gb in [fwd, rev]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice test!
I just added a value check on the result below.
array[[2, 0, 1]].resample(time="1D") | ||
|
||
reverse = array.isel(time=slice(-1, None, -1)) | ||
with pytest.raises(ValueError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new test to make sure we error when trying to resample with a decreasing time index.
Hi @dcherian, I added a note to whats-new. Thanks for your patience, still got a lot to learn :D |
This one is failing on CI / ubuntu-latest py3.9 bare-minimum, is it taking a path without flox installed perhaps?
|
…monotonic-variable * main: (995 commits) Adding `open_datatree` backend-specific keyword arguments (pydata#9199) [pre-commit.ci] pre-commit autoupdate (pydata#9202) Restore ability to specify _FillValue as Python native integers (pydata#9258) add backend intro and how-to diagram (pydata#9175) Fix copybutton for multi line examples in double digit ipython cells (pydata#9264) Update signature for _arrayfunction.__array__ (pydata#9237) Add encode_cf_datetime benchmark (pydata#9262) groupby, resample: Deprecate some positional args (pydata#9236) Delete ``base`` and ``loffset`` parameters to resample (pydata#9233) Update dropna docstring (pydata#9257) Grouper, Resampler as public api (pydata#8840) Fix mypy on main (pydata#9252) fix fallback isdtype method (pydata#9250) Enable pandas type checking (pydata#9213) Per-variable specification of boolean parameters in open_dataset (pydata#9218) test push Added a space to the documentation (pydata#9247) Fix typing for test_plot.py (pydata#9234) Allow mypy to run in vscode (pydata#9239) Revert "Test main push" ...
Co-authored-by: Michael Niklas <[email protected]>
Thanks @JoelJaeschke sorry for the really long delay here! |
This fixes GH6220 which makes it possible to use the fastpath for .groupby for monotonically increasing and decreasing values.
whats-new.rst
api.rst