Better ordering of coords in repr#11091
Merged
jsignell merged 6 commits intopydata:mainfrom Jan 20, 2026
Merged
Conversation
jsignell
commented
Jan 16, 2026
| return (dims.index(name), 0) | ||
|
|
||
| # Non-dimension coordinates sorted by their last dim come second (1) | ||
| for d in var.dims[::-1]: |
Member
Author
There was a problem hiding this comment.
I switched this to look at dims in reverse order because this feels like the right order:
>>> import numpy as np
>>> import xarray as xr
>>> temperature = np.arange(25).reshape(5, 5)
>>> pressure = np.arange(50, 75).reshape(5, 5)
>>> da = xr.DataArray(
... data=temperature,
... dims=["x", "y"],
... coords=dict(
... lon=("x", np.arange(10, 15)),
... lat=("y", np.arange(20, 25)),
... Pressure=(["x", "y"], pressure),
... ),
... name="Temperature",
... )
>>> da
<xarray.DataArray 'Temperature' (x: 5, y: 5)> Size: 200B
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])
Coordinates:
lon (x) int64 40B 10 11 12 13 14
lat (y) int64 40B 20 21 22 23 24
Pressure (x, y) int64 200B 50 51 52 53 54 55 56 57 ... 68 69 70 71 72 73 74
Dimensions without coordinates: x, y
ianhi
approved these changes
Jan 19, 2026
Collaborator
ianhi
left a comment
There was a problem hiding this comment.
nice! thanks for this. I left one comment about the comments but otherwise seems good by me
ianhi
reviewed
Jan 19, 2026
Member
Author
|
Just checked GenericMappingTools/pygmt#4143 since that was linked as fallout from the original coord ordering PR. It looks like they had a simple case (all dimension coordinates) so the repr should be the same with the PR in as it was after #10778. No change needed on that library |
tonybaloney
pushed a commit
to tonybaloney/swe-complex-xarray
that referenced
this pull request
Mar 19, 2026
PR: pydata#11091 Issue: pydata#11039 Base commit: 9fe835f Changed lines: 65
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update coords order in repr based off @ianhi's suggestions in #11039. This undoes a bunch of the docstring changes that came in on #10778 but the order feels more intuitive to me with this PR. All of the original issues are still improved:
Examples
From #712:
From #4515
From #11039
whats-new.rst