← Back to Pull requests

Fix broadcast with an index spanning several dimensions #11615

Closed
unknown closed this pull request without merging on Sep 28, 2026 18:57 UTC
View on GitHub
unknown unknown commented on Sep 26, 2026 17:20 UTC
Author

Description

Broadcasting a raster whose x and y coordinates share one index (RasterIndex from the custom-index guide) against a band vector fails:

xr.broadcast(raster, xr.DataArray([1, 2], dims="band"))
# ValueError: new dimensions {'y': 100, 'band': 2} must be a superset of existing dimensions ('y', 'x')

  • _get_broadcast_dims_map_common_coords skips a dimension with if dim not in common_coords.

  • While handling y, the index contributes both y and x to common_coords, so x never enters the dimension map.
  • The fix collects dimensions and index coordinates separately: a dimension enters the map the first time it is seen, and an index's coordinates are collected the first time an indexed argument carries that dimension. Default PandasIndex objects contribute only their own name, so nothing changes for them. Preserving the custom index itself through broadcast is a separate change; exclude naming one dimension of such an index still fails as on main. Related to #6481.

    <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"))
    raster = da.set_xindex(["x", "y"], RasterIndex)
    xr.broadcast(raster, xr.DataArray([1, 2], dims="band"))
    

    </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 verified this work.

    Diff: 314 lines (+235 / -79) across 3 files Reviewer: matthiasschabel Review duration: 2976m
    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 · 314 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.344
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #11615"
    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