← Back to Pull requests

Raise when Dataset.update would replace an index with one of another type #11621

Open
unknown opened this pull request with 329 lines diff across 4 files
View on GitHub
unknown unknown commented on Sep 27, 2026 16:55 UTC
Author

Description

ds["nir"] = nir silently swaps a Dataset's custom index (e.g. the RasterIndex from the custom-index guide) for the default PandasIndex that nir carries. Same for assign and update. This now raises and points at drop_indexes:

AlignmentError: cannot update Dataset: coordinate 'x' is indexed by RasterIndex on the Dataset but by PandasIndex in the value for 'nir'. Drop the incoming index first, e.g. with .drop_indexes(['x', 'y']).

  • Alignment lets it through because the labels are equal, then the merge gives the incoming object priority, so its index wins.

  • The new check runs per coordinate the Dataset already indexes. Same index type over the same coordinates passes as before, so updates where both sides use PandasIndex are unaffected.

  • A key in the update mapping that names the coordinate (ds.update({"x": ...})) still replaces it.
  • This also raises for a Dataset with a RangeIndex when the assigned array carries its own labels; that used to silently become a PandasIndex. Listed under breaking changes.

    <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
    
    coords = {"x": np.arange(50), "y": np.arange(100)}
    ds = xr.DataArray(np.zeros((100, 50)), coords=coords, dims=("y", "x")).set_xindex(["x", "y"], RasterIndex).to_dataset(name="red")
    nir = xr.DataArray(np.ones((100, 50)), coords=coords, dims=("y", "x"))
    ds["nir"] = nir
    print(ds.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 tests at my direction; Claude (Opus 5.5) and Codex (gpt-6-astra) reviewed. I have read and validated every line.

    Diff: 329 lines (+246 / -83) across 4 files Reviewer: matthiasschabel Review duration: 92499m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.49) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.49 · 329 lines diff across 4 files
    0.49
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.347
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #11621"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 49.1% (MEDIUM) · Higher = larger blast radius
    49.1%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 27.1% · Safe to merge
    27.1%
    Repository