Skip to content

Commit

Permalink
Restored old xarray coord order inference behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 19, 2018
1 parent fad207e commit 1f3823c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ def retrieve_unit_and_label(dim):
vdims = [retrieve_unit_and_label(vd) for vd in vdims]
if kdims is None:
xrdims = list(data.dims)
xrcoords = list(data.coords)
print(xrcoords)
kdims = [name for name in data.indexes.keys()
if isinstance(data[name].data, np.ndarray)]
kdims = sorted(kdims, key=lambda x: (xrdims.index(x) if x in xrdims else float('inf'), x))
kdims = sorted(kdims, key=lambda x: (xrcoords.index(x) if x in xrcoords else float('inf'), x))
if set(xrdims) != set(kdims):
virtual_dims = [xd for xd in xrdims if xd not in kdims]
for c in data.coords:
Expand Down
9 changes: 9 additions & 0 deletions tests/core/data/testdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,15 @@ def test_xarray_override_dims(self):
data_dim = Dimension("data_name")
self.assertEqual(ds_from_ds.vdims[0], data_dim)

def test_xarray_coord_ordering(self):
import xarray as xr
data = np.zeros((3,4,5))
coords = OrderedDict(b=range(3), c=range(4), a=range(5))
darray = xr.DataArray(data, coords=coords, dims=['b', 'c', 'a'])
dataset = xr.Dataset({'value': darray}, coords=coords)
ds = Dataset(dataset)
self.assertEqual(ds.kdims, ['b', 'c', 'a'])

def test_dataset_array_init_hm(self):
"Tests support for arrays (homogeneous)"
raise SkipTest("Not supported")
Expand Down

0 comments on commit 1f3823c

Please sign in to comment.