Skip to content

Order coords to match dims in repr - #10778

Merged
max-sixty merged 8 commits into
pydata:mainfrom
jsignell:dim-ordered-coords
Oct 7, 2025
Merged

Order coords to match dims in repr#10778
max-sixty merged 8 commits into
pydata:mainfrom
jsignell:dim-ordered-coords

Conversation

@jsignell

@jsignelljsignell commented Sep 22, 2025

Copy link
Copy Markdown
Member

Demo

From #712:

In [4]: fromcollectionsimport* ...: importnumpyasnp ...: fromxarrayimport* ...: ...: d1=DataArray(np.empty((2, 2)), coords=OrderedDict([("foo", [0, 1]), ("bar", [0, 1])]), dims=["foo", "bar"]) ...: d2=DataArray(np.empty((2, 2)), coords=OrderedDict([("bar", [0, 1]), ("foo", [0, 1])]), dims=["bar", "foo"]) ...: ...: ds=Dataset({"d1": d1, "d2": d2}) ...: ...: print(ds.d1) ...: print(ds.d2) <xarray.DataArray'd1' (foo: 2, bar: 2)>Size: 32Barray([[4.70561893e-310, 0.00000000e+000],
[4.54093764e-293, 1.78484740e+161]])
Coordinates:
*foo (foo) int6416B01*bar (bar) int6416B01<xarray.DataArray'd2' (bar: 2, foo: 2)>Size: 32Barray([[ 9.98924668e+201, 8.70970817e-191],
[-2.16505045e+052, 8.30088883e-055]])
Coordinates:
*bar (bar) int6416B01*foo (foo) int6416B01
fromcollectionsimport*importnumpyasnpimportxarrayasxrd1=DataArray(np.empty((2, 2)), coords=OrderedDict([("foo", [0, 1]), ("bar", [0, 1])]))
d2=DataArray(np.empty((2, 2)), coords=OrderedDict([("bar", [0, 1]), ("foo", [0, 1])]))
ds=Dataset({"d1": d1, "d2": d2})
print(ds.d1)
print(ds.d2)

From #4515:

importxarrayasxrimportnumpyasnpds=xr.Dataset()
ds.coords["as"] =10ds["var"] =xr.DataArray(np.ones((10,)), dims="x", coords={"x": np.arange(10)})
ds
image

Comment threadxarray/tests/test_formatting_html.py Outdated
Comment threadxarray/tests/test_formatting_html.py Outdated

@IllviljanIllviljan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. There were quite a few fixes needed in our tests so I guess it might be noticeable for others.
But they could use something like https://github.com/max-sixty/pytest-accept to fix their reprs.

@IllviljanIllviljan added the plan to merge Final call for comments label Oct 4, 2025
@max-sixty
max-sixty merged commit 7659b2d into pydata:mainOct 7, 2025
47 checks passed
@jsignell
jsignell deleted the dim-ordered-coords branch October 7, 2025 18:55
weiji14 added a commit to GenericMappingTools/pygmt that referenced this pull request Oct 8, 2025
Specifically on `_GMT_IMAGE.to_xarray` and `GMTBackendEntrypoint`, due to changes in xarray=2025.10.0 from repr changes to the coords ordering, xref pydata/xarray#10778. Also removed ellipsis and added the size of the DataArray and coordinates in kB.
weiji14 added a commit to GenericMappingTools/pygmt that referenced this pull request Oct 9, 2025
…pr (#4145)
Specifically on `_GMT_IMAGE.to_xarray` and `GMTBackendEntrypoint`, due to
changes in xarray=2025.10.1 from repr changes to the coords ordering,
xref pydata/xarray#10778. Also removed ellipsis and
added the size of the DataArray and coordinates in kB.
---------
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
@keewiskeewis mentioned this pull request Dec 19, 2025
@jsignelljsignell mentioned this pull request Jan 16, 2026
3 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataArrays should display their coordinates in the natural order

3 participants

@jsignell@Illviljan@max-sixty