Skip to content

Commit

Permalink
Fixed bugs introduced by irregular data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 30, 2017
1 parent 2899a88 commit 73696bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
8 changes: 4 additions & 4 deletions holoviews/core/data/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions holoviews/core/data/iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 12 additions & 11 deletions holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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]):
Expand Down

0 comments on commit 73696bb

Please sign in to comment.