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 d7f6a69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion holoviews/core/data/xarray.py
Expand Up @@ -127,9 +127,10 @@ 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)
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
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 d7f6a69

Please sign in to comment.