Skip to content

Commit

Permalink
Merge pull request #643 from ioam/interface_enhancement
Browse files Browse the repository at this point in the history
Interface initialization improvements
  • Loading branch information
philippjfr committed Apr 26, 2016
2 parents a5cdfd5 + 01575ee commit 4c260b6
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions holoviews/core/data/__init__.py
Expand Up @@ -119,8 +119,8 @@ def __init__(self, data, **kwargs):
kwargs.get('kdims'),
kwargs.get('vdims'),
datatype=kwargs.get('datatype'))
(data, kdims, vdims, self.interface) = initialized
super(Dataset, self).__init__(data, **dict(kwargs, kdims=kdims, vdims=vdims))
(data, self.interface, dims, extra_kws) = initialized
super(Dataset, self).__init__(data, **dict(extra_kws, **dict(kwargs, **dims)))
self.interface.validate(self)


Expand Down Expand Up @@ -425,7 +425,7 @@ def columns(self, dimensions=None):
dimensions = [self.get_dimension(d) for d in dimensions]
return {d.name: self.dimension_values(d) for d in dimensions}


@property
def to(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions holoviews/core/data/array.py
Expand Up @@ -64,7 +64,7 @@ def init(cls, eltype, data, kdims, vdims):
kdims = eltype.kdims
if vdims is None:
vdims = eltype.vdims
return data, kdims, vdims
return data, {'kdims':kdims, 'vdims':vdims}, {}

@classmethod
def validate(cls, dataset):
Expand Down Expand Up @@ -230,4 +230,3 @@ def aggregate(cls, dataset, dimensions, function, **kwargs):


Interface.register(ArrayInterface)

3 changes: 1 addition & 2 deletions holoviews/core/data/dictionary.py
Expand Up @@ -73,7 +73,7 @@ def init(cls, eltype, data, kdims, vdims):
data.update(unpacked)
else:
data = OrderedDict([(d, np.array(data[d])) for d in dimensions])
return data, kdims, vdims
return data, {'kdims':kdims, 'vdims':vdims}, {}


@classmethod
Expand Down Expand Up @@ -243,4 +243,3 @@ def aggregate(cls, dataset, kdims, function, **kwargs):


Interface.register(DictInterface)

2 changes: 1 addition & 1 deletion holoviews/core/data/grid.py
Expand Up @@ -72,7 +72,7 @@ def init(cls, eltype, data, kdims, vdims):
raise ValueError('Key dimension values and value array %s '
'shape do not match. Expected shape %s, '
'actual shape: %s' % (vdim, expected, shape))
return data, kdims, vdims
return data, {'kdims':kdims, 'vdims':vdims}, {}


@classmethod
Expand Down
5 changes: 2 additions & 3 deletions holoviews/core/data/interface.py
Expand Up @@ -72,15 +72,15 @@ def initialize(cls, eltype, data, kdims, vdims, datatype=None):
# Iterate over interfaces until one can interpret the input
for interface in prioritized:
try:
(data, kdims, vdims) = interface.init(eltype, data, kdims, vdims)
(data, dims, extra_kws) = interface.init(eltype, data, kdims, vdims)
break
except:
pass
else:
raise ValueError("None of the available storage backends "
"were able to support the supplied data format.")

return data, kdims, vdims, interface
return data, interface, dims, extra_kws


@classmethod
Expand Down Expand Up @@ -202,4 +202,3 @@ def shape(cls, dataset):
@classmethod
def length(cls, dataset):
return len(dataset.data)

2 changes: 1 addition & 1 deletion holoviews/core/data/iris.py
Expand Up @@ -109,7 +109,7 @@ def init(cls, eltype, data, kdims, vdims):
if vdims is None:
vdims = [Dimension(data.name(), unit=str(data.units))]

return data, kdims, vdims
return data, {'kdims':kdims, 'vdims':vdims}, {'group':data.name()}


@classmethod
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/ndelement.py
Expand Up @@ -61,7 +61,7 @@ def init(cls, eltype, data, kdims, vdims):
data = NdElement(data, kdims=kdims, vdims=vdims)
elif not isinstance(data, NdElement):
raise ValueError("NdElementInterface interface couldn't convert data.""")
return data, kdims, vdims
return data, {'kdims':kdims, 'vdims':vdims}, {}


@classmethod
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/pandas.py
Expand Up @@ -76,7 +76,7 @@ def init(cls, eltype, data, kdims, vdims):
zip(columns, data)])
else:
data = pd.DataFrame(data, columns=columns)
return data, kdims, vdims
return data, {'kdims':kdims, 'vdims':vdims}, {}


@classmethod
Expand Down

0 comments on commit 4c260b6

Please sign in to comment.