Repository navigation
Conversation
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
This branch has not been deployed
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.
Description
Empty slices with a negative step on lazily indexed backend arrays now select nothing, as in NumPy.
_decompose_slicereturnsslice(0, 0), slice(None)when the negative-step range is empty, instead of reachingrange(...)[-1](theIndexErrorforslice(1, 1, -1)).normalize_slicereturnsslice(0, 0, 1)whenslice.indicesgives a start of-1. That only happens for an empty negative-step slice that starts before the axis (for exampleslice(-4, None, -1)on 3 elements). Before, the result wasslice(-1, None, -1), which the lazy wrapper then read as "the whole axis, reversed".Tests: new cases in
test_normalize_indexerandtest_decompose_slice, plustest_lazily_indexed_empty_negative_step_slice, which runs both slices from the issue throughLazilyIndexedArrayon aBackendArraywithIndexingSupport.BASIC. All of them fail onmainand pass with this change. Locally,xarray/tests/test_indexing.pygives 175 passed, 8 skipped. The twoTestMemoryCachedArrayasync tests fail with and without this change because pytest-asyncio isn't installed in my environment.ruff checkandruff format --checkpass on the changed files.Checklist
whats-new.rstAI Disclosure
Tools: Codex (first draft of the fix and the unit-test cases; I added the end-to-end lazy-array test and reran the tests myself).