Fix Cube.rolling_window with lazy auxiliary coordinates (#6480)#7123
Open
gaoflow wants to merge 1 commit into
Open
Fix Cube.rolling_window with lazy auxiliary coordinates (#6480)#7123gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
rolling_window built each window's coordinate bounds with new_bounds[:, (0, -1)]. A tuple index is treated by Dask as a multidimensional index, so a lazy coordinate along the windowed dimension raised a TypeError. Index with the list [0, -1] instead, which numpy and Dask both treat as selecting the first and last column, giving an identical (and still lazy) result. Fixes SciTools#6480.
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.
🚀 Pull Request
Description
Closes #6480 (and the duplicate #6639).
:meth:
iris.cube.Cube.rolling_windowraised aTypeErrorwhen the cube had a lazy auxiliary coordinate running along the windowed dimension:Cause
When building the new coordinate bounds,
rolling_windowselects the first and last point of each window with:A tuple index is interpreted by Dask as a multidimensional index (and so it tries to use
0and-1as indices into successive axes), which fails for a lazy array. NumPy happens to tolerate the tuple here, so the bug only surfaces for lazy coordinates.Fix
Index with the list
[0, -1]instead. NumPy and Dask both treat a list as selecting the first and last column, so the result is identical for real arrays and now also works (and stays lazy) for lazy ones. This is the fix hinted at by @pp-mo on the issue. Both the numeric and string-coordinate branches are updated.Verification
Test_rolling_window::test_lazy_aux_coord— asserts a lazy aux-coord no longer fails, stays lazy (points and bounds), and equals the real-array result. It fails onmainand passes here.Test_rolling_windowandtests/unit/util/test_rolling_window.pysuites pass (25 tests).ruff check/ruff formatclean.