Skip to content

Commit

Permalink
Merge pull request #559 from ioam/gridcolumns_fixes
Browse files Browse the repository at this point in the history
Various small fixes for GridColumns
  • Loading branch information
jlstevens committed Mar 19, 2016
2 parents 2f2aade + 2690727 commit 87a4414
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions holoviews/core/data.py
Expand Up @@ -1386,13 +1386,13 @@ def init(cls, eltype, data, kdims, vdims):

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]
expected = tuple([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'
if shape != expected and not (not expected and shape == (1,)):
raise ValueError('Key dimension values and value array %s '
'shape do not match. Expected shape %s, '
'actual shape: %s' % (expected, vdim, shape))
'actual shape: %s' % (vdim, expected, shape))
return data, kdims, vdims


Expand Down Expand Up @@ -1456,10 +1456,15 @@ def groupby(cls, columns, dim_names, container_type, group_type, **kwargs):

# Iterate over the unique entries applying selection masks
grouped_data = []
for unique_key in zip(util.cartesian_product(keys)):
for unique_key in zip(*util.cartesian_product(keys)):
group_data = cls.select(columns, **dict(zip(dim_names, unique_key)))
for vdim in columns.vdims:
group_data[vdim.name] = np.squeeze(group_data[vdim.name])
if np.isscalar(group_data):
group_data = {columns.vdims[0].name: np.atleast_1d(group_data)}
for dim, v in zip(dim_names, unique_key):
group_data[dim] = np.atleast_1d(v)
else:
for vdim in columns.vdims:
group_data[vdim.name] = np.squeeze(group_data[vdim.name])
group_data = group_type(group_data, **group_kwargs)
grouped_data.append((tuple(unique_key), group_data))

Expand Down
3 changes: 3 additions & 0 deletions tests/testcolumns.py
Expand Up @@ -475,3 +475,6 @@ def test_columns_sort_vdim_hm(self):
with self.assertRaisesRegexp(Exception, exception):
self.columns_hm.sort('y')


def test_columns_groupby(self):
self.assertEqual(self.columns_hm.groupby('x').keys(), list(self.xs))

0 comments on commit 87a4414

Please sign in to comment.