Skip to content

Conversation

@sshekhar563
Copy link

Summary #11039

This PR improves the ordering of coordinates in the string representation (repr) of xarray objects to make them more intuitive and easier to understand by grouping related coordinates together.

Problem

Previously, coordinates were ordered simply by their position in the dataset's dimension tuple, which could lead to confusing representations where related coordinates were scattered throughout the output. For example:

# Before (confusing ordering)
Coordinates:
  * x        (x) int64 16B -1 -2
  * y        (y) int64 24B 0 1 2
    a        (x) int64 16B 4 5      # Related to x but far from it
    b        int64 8B -10

# After (intuitive grouping)
Coordinates:
  * x        (x) int64 16B -1 -2
    a        (x) int64 16B 4 5      # Now grouped with x
  * y        (y) int64 24B 0 1 2
    b        int64 8B -10

sshekhar563 and others added 6 commits December 20, 2025 13:10
- Group non-dimension coordinates with their associated dimensions
- Dimension coordinates appear first in dataset dimension order
- Non-dimension coordinates are grouped by their first matching dimension
- Coordinates with no matching dimensions appear at the end
- Fixes pydata#11039

This makes the coordinate representation more intuitive by visually
grouping related coordinates together, making it easier to understand
the structure of complex datasets with many coordinates.
The new coordinate ordering groups non-dimension coordinates right after
their associated dimension coordinates. Updated doctests in:
- xarray/core/common.py (assign_coords)
- xarray/core/dataarray.py (DataArray class, pad, reset_coords, set_index)
- xarray/core/dataset.py (Dataset class, set_index, filter_by_attrs)
- xarray/structure/concat.py (concat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant