Return an empty result from rolling and cumulative on a zero-length dimension - #11572
Open
chiruu12 wants to merge 3 commits into
Open
Return an empty result from rolling and cumulative on a zero-length dimension#11572chiruu12 wants to merge 3 commits into
chiruu12 wants to merge 3 commits into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
cumulativederives its window from the size of the dimension, so on a dimension oflength 0 it asks
Rollingfor a window of 0 and gets back `ValueError: window must beAn empty selection is ordinary, so this shows up on data that happens to filter down to
nothing rather than on anything malformed.
The window guard is right for a window the caller picked, so
cumulativenow floors itsderived window at 1 instead. That alone was not enough.
rolling_windowpads bywin - 1, which leaves a zero-length dimension shorter than the window, andsliding_window_viewrefuses that outright, so plainrollingfailed on an emptydimension too:
A zero-length dimension yields zero windows. Padding it out to one full window gives
sliding_window_viewsomething it accepts, and the one window it produces is sliced backoff. Slicing rather than building a fresh empty array keeps the data in whatever
namespace it arrived in.
Not fixed here: the same call on a dask-backed array still fails, in
dask.array.padwith
ZeroDivisionErrorfor a window above 1 andThe overlapping depth 1 is larger than your array 0for a window of 1. Both reproduce on an unmodified main, so this is a dasklimitation upstream of the change rather than something it introduced. Happy to look at
it separately if you want it in scope.
Tests cover both entry points, both container types,
dimas a string and as a list,centered and not, windows of 1 and 3, and two empty dimensions at once. All eight fail on
the commit before the fix.
test_rolling.py test_dataarray.py test_dataset.py test_computation.py: 4300 passed. Threefailures in
test_dataset.py(test_sel, twotest_chunk_by_season_resampler) reproduceon an unmodified main and look like a local pandas version.
test_variable.pydoes notcollect on main here for the same reason.
ruff checkandruff format --checkclean.