Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restored old xarray coord order inference behavior #2579

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
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
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