Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various small fixes for GridColumns #559

Merged
merged 4 commits into from
Mar 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions holoviews/core/data.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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))