Repository navigation
fix(indexing): drop stale chunksizes encoding when dims change (#11028) - #11928
Open
aniruddhaadak80 wants to merge 3 commits into
Open
aniruddhaadak80 wants to merge 3 commits into
aniruddhaadak80 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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
Closes #11028.
encoding["chunksizes"]is a positional tuple aligned with a variable's dimensions. Whenisel()removes a dimension (e.g. selects a single index), the variable's dims change but the encoding is copied unchanged, leaving a stale N-dimensionalchunksizeson an N-1 dimensional variable:Writers then have to detect and discard the mismatched value, so a user's chunking preference is silently lost.
The fix drops
encoding["chunksizes"]inVariable._finalize_indexing_resultandIndexVariable._finalize_indexing_resultwhen the resultingdimsdiffer from the sourcedims. Other encoding entries (e.g._FillValue) are untouched, andchunksizesis preserved for indexing that keeps the same dimensions, such asisel(time=slice(0, 2)). No public API change.This is a targeted step toward the broader goal expressed in the issue discussion of removing encoding after the first operation; it deliberately only removes the one entry that is invalid after a dim change.
A
doc/whats-new.rstentry was added under the unreleased "Bug Fixes" section.Checklist
encoding['chunksizes']can become stale afterisel()removes a dimension #11028whats-new.rstapi.rst(no new functions or methods)Tests
New test in
xarray/tests/test_dataset.pycovering both the dimension-dropping case (stalechunksizesremoved, other encoding kept) and the dimension-preserving slice (chunksizes kept).Actual results in a worktree-local environment (Python 3.12, NumPy 2.5.3, pandas 3.0.6, Windows). A local
sitecustomize.pyonPYTHONPATHgave the tagless editabledaskcheckout a parseable__version__; nothing from it is in the diff.The only difference is the one added test. The 22 failures are pre-existing in this environment: pandas 3.0.6 refuses to import its optional xarray integration because the tagless editable install reports
xarray 0.0.0. They are categorical / extension-array / from_dataframe tests and fail identically without the fix.Limitations
chunksizesis dropped; other dimension-dependent encoding keys, if any, are out of scope.AI Disclosure
Tools: OpenCode (AI coding agent)
An AI coding agent located the encoding copy in the indexing finalizers, drafted the fix and the regression test, and ran the verification above. I reviewed the diff and each claimed result.