Skip to content

Commit

Permalink
Improved GridColumns validation
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 9, 2016
1 parent 49e729a commit 7d5dc26
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions holoviews/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,18 @@ def reshape(cls, eltype, data, kdims, vdims):
if vdims is None:
vdims = eltype.vdims

if not vdims:
raise ValueError('GridColumns interface requires at least '
'one value dimension.')

dimensions = [d.name if isinstance(d, Dimension) else
d for d in kdims + vdims]
if isinstance(data, tuple):
data = {d: v for d, v in zip(dimensions, data)}
elif not isinstance(data, dict):
raise ValueError('GridColumns must be instantiated as a '
'dictionary or tuple')

if 'vdims' in data:
vdim_array = data.pop('vdims')
for i, vdim in enumerate(vdims):
Expand All @@ -1365,21 +1377,21 @@ def reshape(cls, eltype, data, kdims, vdims):
if not isinstance(data[name], np.ndarray):
data[name] = np.array(data[name])

kdim_names = [d.name if isinstance(d, Dimension) else d for d in kdims]
vdim_names = [d.name if isinstance(d, Dimension) else d for d in vdims]
expected = [len(data[kd]) for kd in kdim_names]
for vdim in vdim_names:
shape = data[vdim].shape
if shape != tuple(expected):
raise ValueError('Key dimension values and value array %s'
'shape do not match. Expected shape %s, '
'actual shape: %s' % (expected, vdim, shape))
return data, kdims, vdims


@classmethod
def validate(cls, columns):
if not columns.vdims:
return
expected = [len(columns.data[kd.name])
for kd in columns.kdims]
for vdim in columns.vdims:
shape = columns.data[vdim.name].shape
if shape != tuple(expected):
raise ValueError('Key dimension values and value array %s'
'shape do not match. Expected shape %s, '
'actual shape: %s' % (expected, vdim, shape))
DataColumns.validate(columns)


@classmethod
Expand Down Expand Up @@ -1483,6 +1495,10 @@ def coord_mask(cls, columns, arr, ind):
@classmethod
def select(cls, columns, selection_mask=None, **selection):
dimensions = columns.dimensions('key', label=True)
val_dims = [vdim for vdim in columns.vdims if vdim in selection]
if val_dims:
raise IndexError('Cannot slice value dimensions on dense '
'data, convert to sparse format first')
selection = [(d, selection.get(d)) for d in dimensions]
data = {}
value_select = []
Expand Down

0 comments on commit 7d5dc26

Please sign in to comment.