← Back to Pull requests

Drop a multi-coordinate index whole in Dataset reductions #11616

Closed
unknown closed this pull request without merging on Oct 01, 2026 20:56 UTC
View on GitHub
unknown unknown commented on Sep 26, 2026 18:14 UTC
Author

Description

Reducing a raster dataset along x leaves the shared x/y index (RasterIndex from the custom-index guide) attached to y although it still spans the dimension that was just removed:

ds.mean("x").xindexes        # {'y': RasterIndex} whose internal indexes still cover 'x' and 'y'

  • Dataset.reduce, Dataset.quantile and Dataset._integrate_one filter indexes by coordinate name (if k in variables).

  • DataArray reductions use filter_indexes_from_coords since #11286, which drops an index unless all of its coordinates survive.
  • The fix uses filter_indexes_from_coords at the three Dataset sites, so ds.mean("x") drops the index from y too. PandasIndex and PandasMultiIndex are unaffected: their coordinates all survive or all go together. Reductions over a dimension the index does not own keep it intact, before and after.

    Related to #11215, not closing it: that issue asks to keep a multi-coordinate index on whichever coordinates survive.

    <details>
    <summary>Reproducer with RasterIndex</summary>

    import numpy as np, xarray as xr
    from xarray import Index
    from xarray.core.indexes import PandasIndex
    
    class RasterIndex(Index):
        def __init__(self, xy_indexes):
            self._xy_indexes = xy_indexes
        @classmethod
        def from_variables(cls, variables, *, options):
            return cls({k: PandasIndex.from_variables({k: v}, options=options) for k, v in variables.items()})
        def create_variables(self, variables=None):
            out = {}
            for index in self._xy_indexes.values():
                out.update(index.create_variables(variables))
            return out
    
    da = xr.DataArray(np.zeros((100, 50)), coords={"x": np.arange(50), "y": np.arange(100)}, dims=("y", "x"))
    ds = da.set_xindex(["x", "y"], RasterIndex).to_dataset(name="red")
    print(ds.mean("x").xindexes)
    

    </details>

    Checklist

  • Tests added

  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • AI Disclosure

  • This PR contains AI-generated content.

  • - [x] I have tested any AI-generated content in my PR.
    - [x] I take responsibility for any AI-generated content in my PR.
    Tools: Codex (gpt-6-sol) drafted the change and test at my direction; Claude (Opus 5.5) and Codex (gpt-6-astra) reviewed. I have read and validated this work.

    Diff: 310 lines (+232 / -78) across 3 files Reviewer: matthiasschabel Review duration: 7362m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 310 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.343
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #11616"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.3% (MEDIUM) · Higher = larger blast radius
    40.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%
    Repository