-
-
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
Merged
dcherian
merged 17 commits into
pydata:main
from
JoelJaeschke:fix-6220-use-fast-path-when-grouping-unique-monotonic-variable
Jul 26, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f60e0c7
Fix GH6220
JoelJaeschke 495a60d
Merge remote-tracking branch 'upstream/main' into fix-6220-use-fast-p…
JoelJaeschke 2ec3fbe
Merge remote-tracking branch 'upstream/main' into fix-6220-use-fast-p…
JoelJaeschke 1636b74
Implemented groupby tests as described by feedback
JoelJaeschke 38ff104
Implemented groupby tests as described by feedback
JoelJaeschke 7959119
Merge branch 'main' into fix-6220-use-fast-path-when-grouping-unique-…
JoelJaeschke 192b2f6
Minor test.
dcherian c50c5db
Test resampling error with monotonic decreasing data.
dcherian 3856b24
Fix test.
dcherian 27e77c7
Merge branch 'main' into fix-6220-use-fast-path-when-grouping-unique-…
JoelJaeschke 939b9b8
Added feature to whats-new.rst
JoelJaeschke 16e29e2
Merge branch 'main' into fix-6220-use-fast-path-when-grouping-unique-…
dcherian bed344c
Update whats-new.rst
dcherian 93de184
Merge branch 'main' into fix-6220-use-fast-path-when-grouping-unique-…
dcherian ad738ff
main
dcherian 2f2a5e1
flox test
dcherian 95085b5
Update xarray/tests/test_groupby.py
dcherian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1792,6 +1792,23 @@ def test_groupby_fillna(self) -> None: | |
actual = a.groupby("b").fillna(DataArray([0, 2], dims="b")) | ||
assert_identical(expected, actual) | ||
|
||
@pytest.mark.parametrize("use_flox", [True, False]) | ||
def test_groupby_fastpath_for_monotonic(self, use_flox: bool) -> None: | ||
# Fixes https://github.com/pydata/xarray/issues/6220 | ||
# Fixes https://github.com/pydata/xarray/issues/9279 | ||
index = [1, 2, 3, 4, 7, 9, 10] | ||
array = DataArray(np.arange(len(index)), [("idx", index)]) | ||
array_rev = array.copy().assign_coords({"idx": index[::-1]}) | ||
fwd = array.groupby("idx", squeeze=False) | ||
rev = array_rev.groupby("idx", squeeze=False) | ||
|
||
for gb in [fwd, rev]: | ||
assert all([isinstance(elem, slice) for elem in gb._group_indices]) | ||
|
||
with xr.set_options(use_flox=use_flox): | ||
assert_identical(fwd.sum(), array) | ||
assert_identical(rev.sum(), array_rev) | ||
|
||
|
||
class TestDataArrayResample: | ||
@pytest.mark.parametrize("use_cftime", [True, False]) | ||
|
@@ -1828,9 +1845,13 @@ def resample_as_pandas(array, *args, **kwargs): | |
expected = resample_as_pandas(array, "24h", closed="right") | ||
assert_identical(expected, actual) | ||
|
||
with pytest.raises(ValueError, match=r"index must be monotonic"): | ||
with pytest.raises(ValueError, match=r"Index must be monotonic"): | ||
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 commentThe 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. |
||
reverse.resample(time="1D").mean() | ||
|
||
@pytest.mark.parametrize("use_cftime", [True, False]) | ||
def test_resample_doctest(self, use_cftime: bool) -> None: | ||
# run the doctest example here so we are not surprised | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.