Repository navigation
Respect drop=True for scalar coordinates an index keeps - #11617
Open
matthiasschabel wants to merge 6 commits into
Open
matthiasschabel wants to merge 6 commits into
matthiasschabel wants to merge 6 commits into
Conversation
isel and sel with drop=True promise to drop the scalar coordinates a selection produces. When the selected coordinate belongs to an index whose isel rebuilds the 0-d coordinate itself, isel_indexes returns it among the index variables and the coordinate was silently kept. Drop such coordinates the way drop_vars would, raising the existing corrupt-index error when only some of an index's coordinates would go. The default PandasIndex returns no index for a scalar selection, so its behaviour is unchanged.
matthiasschabel
force-pushed
the
pr/drop-scalar-index-coords
branch
from
September 26, 2026 20:23
2454f7b to
6a630ad
Compare
matthiasschabel
marked this pull request as ready for review
September 27, 2026 16:27
The Bug Fixes entry added with the fix was dropped while resolving a merge from main around the v2026.09.0 release. Re-add it under the unreleased section, naming DataArray as well as Dataset, since both isel paths changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Reviewed-By: Codex (gpt-6-astra, reasoning effort high)
…coords # Conflicts: # xarray/tests/test_dataset.py
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
Extracting bare pixel samples from a raster with
drop=Truedoes not drop the scalar coordinates when the raster's index keeps them:isel(..., drop=True)andsel(..., drop=True)is that scalar coordinates produced by the selection are dropped.iselrebuilds the selected position as a 0-d coordinate returns it inindex_variables, and theiselpaths copy every index variable into the result beforedropis considered.Nonefromiselfor a scalar selection, so they never hit this and are unchanged.The fix adds
drop_scalar_index_coords, called fromDataArray.isel,Dataset.iselandDataset._isel_fancywhendrop=True. It drops the index-owned scalar coordinates the waydrop_varswould and raises the existing corrupt-index error when only some of an index's coordinates would go (selecting one axis of the raster withdrop=True). Indexes the selection does not touch are left alone;sel(drop=True)delegates toisel.On the new error: the previous result broke the
drop=Truecontract, anddrop_varsalready raises the same error for a partial drop. It only affects custom indexes that keep scalar coordinates, so it is listed under Bug Fixes.Reproducer with a scalar-keeping RasterIndex
The guide's
RasterIndexplus aniselthat keeps the selected position as a 0-d coordinate.Checklist
whats-new.rstAI Disclosure
Tools: Codex (gpt-6-sol) drafted the change and tests at my direction; Claude (Opus 5.5) and Codex (gpt-6-astra) reviewed. I have read and validated every line.