Skip to content

Conversation

jsignell
Copy link
Contributor

@jsignell jsignell commented Sep 22, 2025

Demo

From #712:

In [4]: from collections import * 
   ...: import numpy as np 
   ...: from xarray import * 
   ...:  
   ...: 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: 32B
array([[4.70561893e-310, 0.00000000e+000],
       [4.54093764e-293, 1.78484740e+161]])
Coordinates:
  * foo      (foo) int64 16B 0 1
  * bar      (bar) int64 16B 0 1
<xarray.DataArray 'd2' (bar: 2, foo: 2)> Size: 32B
array([[ 9.98924668e+201,  8.70970817e-191],
       [-2.16505045e+052,  8.30088883e-055]])
Coordinates:
  * bar      (bar) int64 16B 0 1
  * foo      (foo) int64 16B 0 1
from collections import *
import numpy as np
import xarray as xr

d1 = 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:

import xarray as xr
import numpy as np

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

@jsignell jsignell requested a review from Illviljan September 29, 2025 18:37
Copy link
Contributor

@Illviljan Illviljan left a comment

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.

@Illviljan Illviljan added the plan to merge Final call for comments label Oct 4, 2025
@max-sixty max-sixty merged commit 7659b2d into pydata:main Oct 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataArrays should display their coordinates in the natural order

3 participants