Skip to content

Preserve coordinates after non-leading-dimension groupby reductions - #11290

Merged
dcherian merged 4 commits into
pydata:mainfrom
officialasishkumar:fix-11188-groupby-preserve-coords
Sep 28, 2026
Merged

dcherian merged 4 commits into
pydata:mainfrom
officialasishkumar:fix-11188-groupby-preserve-coords

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Description

Fallback groupby reductions can reorder variable dimensions before DataArray._replace_maybe_drop_dims filters coordinates. That path still zipped shapes against the original dimension order, which dropped unrelated coordinates when the reordered dimensions had different lengths.

This switches that branch to use variable.sizes and adds regression coverage for both the helper and the user-visible groupby behavior.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Codex

Use the reordered variable sizes when deciding which coordinates survive _replace_maybe_drop_dims, and add regression coverage for both the internal helper and groupby behavior.

@headtr1ck headtr1ck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Comment thread doc/whats-new.rst Resolved
@headtr1ck headtr1ck added the plan to merge Final call for comments label Sep 27, 2026
Comment thread xarray/tests/test_groupby.py Resolved
@dcherian
dcherian enabled auto-merge (squash) September 28, 2026 13:40
@dcherian
dcherian merged commit c6c47f3 into pydata:main Sep 28, 2026
44 checks passed
@welcome

welcome Bot commented Sep 28, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

TomNicholas added a commit that referenced this pull request Sep 29, 2026
* Update whats-new for v2026.09.0 release

- Rename the unreleased section to v2026.09.0 and add the release summary
  and contributor list
- Move entries for #11348, #11292, #11290 and #11239 that were merged into
  older release sections
- Add missing entries for #11552, #11521, #11486 and #11513
- Add missing PR links, fix the #11547 link and other markup
- Fix the documented default of the use_bottleneck option
- Add contributor names to the typos allow-list

* Mention plot.lines and last Python 3.11 release in whats-new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plan to merge Final call for comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataArray.groupby drops empty coordinates

3 participants