diff --git a/holoviews/core/data/grid.py b/holoviews/core/data/grid.py index 215ce1a128..adbb16694d 100644 --- a/holoviews/core/data/grid.py +++ b/holoviews/core/data/grid.py @@ -88,7 +88,7 @@ def init(cls, eltype, data, kdims, vdims): for vdim in vdim_names: shape = data[vdim].shape error = DataError if len(shape) > 1 else ValueError - if (not expected and shape == (1,)) or len(set((shape,)+shapes)) == 1: + if (not expected and shape == (1,)) or (len(set((shape,)+shapes)) == 1 and len(shape) > 1): # If empty or an irregular mesh pass elif len(shape) != len(expected): @@ -105,7 +105,7 @@ def init(cls, eltype, data, kdims, vdims): @classmethod def irregular(cls, dataset, dim): - return dataset.data[dim.name].ndim > 1 + return dataset.data[dim.name if isinstance(dim, Dimension) else dim].ndim > 1 @classmethod @@ -273,7 +273,7 @@ def ndloc(cls, dataset, indices): selected[kd.name] = coords all_scalar = False for d in dataset.dimensions(): - if d in dataset.kdims and cls.irregular(dataset, d): + if d in dataset.kdims and not cls.irregular(dataset, d): continue arr = dataset.dimension_values(d, flat=False) if all_scalar and len(dataset.vdims) == 1: @@ -392,7 +392,7 @@ def select(cls, dataset, selection_mask=None, **selection): indexed = cls.indexed(dataset, selection) full_selection = [(d, selection.get(d.name, selection.get(d.label))) - for d in dimensions] + for d in dimensions] data = {} value_select = [] for (dim, ind) in full_selection: diff --git a/holoviews/core/data/iris.py b/holoviews/core/data/iris.py index caebdb26b4..96bd1fd10d 100644 --- a/holoviews/core/data/iris.py +++ b/holoviews/core/data/iris.py @@ -132,6 +132,12 @@ def validate(cls, dataset, vdims=True): raise DataError("Iris cubes do not support more than one value dimension", cls) + @classmethod + def irregular(cls, dataset, dim): + "CubeInterface does not support irregular data" + return False + + @classmethod def shape(cls, dataset, gridded=False): if gridded: diff --git a/holoviews/core/data/xarray.py b/holoviews/core/data/xarray.py index 2b55da53ba..ca1a4adb40 100644 --- a/holoviews/core/data/xarray.py +++ b/holoviews/core/data/xarray.py @@ -169,19 +169,20 @@ def groupby(cls, dataset, dimensions, container_type, group_type, **kwargs): @classmethod - def coords(cls, dataset, dim, ordered=False, expanded=False, edges=False): - dim = dataset.get_dimension(dim, strict=True) + def coords(cls, dataset, dimension, ordered=False, expanded=False, edges=False): + dim = dataset.get_dimension(dimension) + dim = dimension if dim is None else dim.name irregular = cls.irregular(dataset, dim) if irregular or expanded: if irregular: - data = dataset.data[dim.name] + data = dataset.data[dim] else: data = util.expand_grid_coords(dataset, dim) if edges: data = cls._infer_interval_breaks(data, axis=1) data = cls._infer_interval_breaks(data, axis=0) return data - data = np.atleast_1d(dataset.data[dim.name].data) + data = np.atleast_1d(dataset.data[dim].data) if ordered and data.shape and np.all(data[1:] < data[:-1]): data = data[::-1] return data @@ -191,12 +192,12 @@ def coords(cls, dataset, dim, ordered=False, expanded=False, edges=False): def values(cls, dataset, dim, expanded=True, flat=True): dim = dataset.get_dimension(dim, strict=True) data = dataset.data[dim.name].data - irregular = cls.irregular(dataset, dim) + irregular = cls.irregular(dataset, dim) if dim in dataset.kdims else False if dim in dataset.vdims or irregular: coord_dims = list(dataset.data[dim.name].dims) if dask and isinstance(data, dask.array.Array): data = data.compute() - if not irregular: + if not irregular and not any(cls.irregular(dataset, d) for d in dataset.kdims): data = cls.canonicalize(dataset, data, coord_dims=coord_dims) return data.T.flatten() if flat else data elif expanded: @@ -226,18 +227,18 @@ def unpack_scalar(cls, dataset, data): @classmethod def ndloc(cls, dataset, indices): - kdims = [d.name for d in dataset.kdims[::-1]] + kdims = [d for d in dataset.kdims[::-1]] adjusted_indices = [] slice_dims = [] for kd, ind in zip(kdims, indices): - if dataset.data[kd].ndim > 1: + if cls.irregular(dataset, kd): coords = [c for c in dataset.data.coords if c not in dataset.data.dims] - dim = dataset.data[kd].dims[coords.index(kd)] - shape = dataset.data[kd].shape[coords.index(kd)] + dim = dataset.data[kd.name].dims[coords.index(kd.name)] + shape = dataset.data[kd.name].shape[coords.index(kd.name)] coords = np.arange(shape) else: coords = cls.coords(dataset, kd, False) - dim = kd + dim = kd.name slice_dims.append(dim) ncoords = len(coords) if np.all(coords[1:] < coords[:-1]):