Skip to content

Commit

Permalink
Merge pull request #820 from ioam/xarray_add_dimension
Browse files Browse the repository at this point in the history
Fix for xarray interface add_dimension implementation
  • Loading branch information
jlstevens authored Aug 18, 2016
2 parents 2b5e4a0 + 1b098d5 commit f501e47
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion holoviews/core/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs):
combined = self.clone(aggregated, kdims=kdims)
for i, d in enumerate(vdims):
dim = d('_'.join([d.name, spread_name]))
combined = combined.add_dimension(dim, ndims+i, error[d], True)
dvals = error.dimension_values(d, False, False)
combined = combined.add_dimension(dim, ndims+i, dvals, True)
return combined

if np.isscalar(aggregated):
Expand Down
7 changes: 5 additions & 2 deletions holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def select(cls, dataset, selection_mask=None, **selection):
if isinstance(v, set):
validated[k] = list(v)
elif isinstance(v, tuple):
validated[k] = slice(v[0], v[1]-sys.float_info.epsilon*10)
upper = None if v[1] is None else v[1]-sys.float_info.epsilon*10
validated[k] = slice(v[0], upper)
elif isinstance(v, types.FunctionType):
validated[k] = v(dataset[k])
else:
Expand Down Expand Up @@ -234,7 +235,9 @@ def add_dimension(cls, dataset, dimension, dim_pos, values, vdim):
if not vdim:
raise Exception("Cannot add key dimension to a dense representation.")
dim = dimension.name if isinstance(dimension, Dimension) else dimension
return dataset.assign(**{dim: values})
arr = xr.DataArray(values, coords=dataset.data.coords, name=dim,
dims=dataset.data.dims)
return dataset.data.assign(**{dim: arr})


Interface.register(XArrayInterface)

0 comments on commit f501e47

Please sign in to comment.