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.

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
2 participants