diff --git a/holoviews/core/data/xarray.py b/holoviews/core/data/xarray.py index 702c95010f..fbbb944445 100644 --- a/holoviews/core/data/xarray.py +++ b/holoviews/core/data/xarray.py @@ -215,9 +215,17 @@ def retrieve_unit_and_label(dim): # not need to be canonicalized if any(len(da.coords[c].shape) > 1 for c in da.coords): continue - undeclared = [ - c for c in da.coords if c not in kdims and len(da[c].shape) == 1 and - da[c].shape[0] > 1] + undeclared = [] + for c in da.coords: + if c in kdims or len(da[c].shape) != 1 or da[c].shape[0] <= 1: + # Skip if coord is declared, represents irregular coordinates or is constant + continue + elif all(d in kdims for d in da[c].dims): + continue # Skip if coord is alias for another dimension + elif any(all(d in da[kd.name].dims for d in da[c].dims) for kd in kdims): + # Skip if all the dims on the coord are present on another coord + continue + undeclared.append(c) if undeclared: raise DataError( 'The coordinates on the %r DataArray do not match the ' diff --git a/holoviews/tests/core/data/test_xarrayinterface.py b/holoviews/tests/core/data/test_xarrayinterface.py index c3623d47aa..a262d5a4cc 100644 --- a/holoviews/tests/core/data/test_xarrayinterface.py +++ b/holoviews/tests/core/data/test_xarrayinterface.py @@ -60,6 +60,14 @@ def get_multi_dim_irregular_dataset(self): 'time': pd.date_range('2014-09-06', periods=3), 'reference_time': pd.Timestamp('2014-09-05')}) + def test_ignore_dependent_dimensions_if_not_specified(self): + coords = OrderedDict([('time', [0, 1]), ('lat', [0, 1]), ('lon', [0, 1])]) + da = xr.DataArray(np.arange(8).reshape((2, 2, 2)), + coords, ['time', 'lat', 'lon']).assign_coords( + lat1=xr.DataArray([2,3], dims=['lat'])) + assert Dataset(da, ['time', 'lat', 'lon'], vdims='value').kdims == ['time', 'lat', 'lon'] + assert Dataset(da, ['time', 'lat1', 'lon'], vdims='value').kdims == ['time', 'lat1', 'lon'] + def test_xarray_dataset_irregular_shape(self): ds = Dataset(self.get_multi_dim_irregular_dataset()) shape = ds.interface.shape(ds, gridded=True)