Skip to content

Commit

Permalink
Cleanup, comments and docstrings for interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 8, 2017
1 parent 8e31fff commit 29a1e17
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
17 changes: 10 additions & 7 deletions holoviews/core/data/__init__.py
Expand Up @@ -200,8 +200,12 @@ def __setstate__(self, state):

def closest(self, coords=[], **kwargs):
"""
Given single or multiple samples along the first key dimension
will return the closest actual sample coordinates.
Given a single coordinate or multiple coordinates as
a tuple or list of tuples or keyword arguments matching
the dimension closest will find the closest actual x/y
coordinates. Different Element types should implement this
appropriately depending on the space they represent, if the
Element does not support snapping raise NotImplementedError.
"""
if self.ndims > 1:
raise NotImplementedError("Closest method currently only "
Expand Down Expand Up @@ -460,9 +464,7 @@ def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs):

ndims = len(dimensions)
min_d, max_d = self.params('kdims').bounds
new_type = type(self)
if (min_d is not None and ndims < min_d) or (max_d is not None and ndims > max_d):
new_type = Dataset
generic_type = (min_d is not None and ndims < min_d) or (max_d is not None and ndims > max_d)

vdims = self.vdims
if spreadfn:
Expand All @@ -475,7 +477,7 @@ def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs):
dim = d('_'.join([d.name, spread_name]))
dvals = error.dimension_values(d, False, False)
combined = combined.add_dimension(dim, ndims+i, dvals, True)
return combined.clone(new_type=new_type)
return combined.clone(new_type=Dataset if generic_type else type(self))

if np.isscalar(aggregated):
return aggregated
Expand All @@ -486,7 +488,8 @@ def aggregate(self, dimensions=None, function=None, spreadfn=None, **kwargs):
except:
datatype = self.params('datatype').default
return self.clone(aggregated, kdims=kdims, vdims=vdims,
new_type=new_type, datatype=datatype)
new_type=Dataset if generic_type else None,
datatype=datatype)


def groupby(self, dimensions=[], container_type=HoloMap, group_type=None,
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/image.py
Expand Up @@ -247,7 +247,7 @@ def aggregate(cls, dataset, kdims, function, **kwargs):
if len(dataset.vdims) == 1:
return data if np.isscalar(data) else data[0]
else:
return {vd.name: v for vd, v in zip(dataset.vdims, data)}
return {vd.name: np.array([v]) for vd, v in zip(dataset.vdims, data)}
elif len(axes) == 1:
return {kdims[0]: cls.values(dataset, axes[0], expanded=False),
dataset.vdims[0].name: data[::-1] if axes[0] else data}
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/interface.py
Expand Up @@ -67,7 +67,7 @@ def initialize(cls, eltype, data, kdims, vdims, datatype=None):
gridded[vd.name] = data.dimension_values(vd, flat=False)
data = tuple(gridded.values())
else:
data = tuple(data.columns())
data = tuple(data.columns().values())
elif isinstance(data, Element):
data = tuple(data.dimension_values(d) for d in kdims+vdims)
elif isinstance(data, util.generator_types):
Expand Down
2 changes: 2 additions & 0 deletions holoviews/element/raster.py
Expand Up @@ -260,6 +260,8 @@ def __setstate__(self, state):
"""
Ensures old-style unpickled Image types without an interface
use the ImageInterface.
Note: Deprecate as part of 2.0
"""
self.__dict__ = state
if isinstance(self.data, np.ndarray):
Expand Down

0 comments on commit 29a1e17

Please sign in to comment.