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

Handle bug in gridded groupby when dropping dimensions #1219

Merged
merged 1 commit into from
Mar 21, 2017
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
4 changes: 2 additions & 2 deletions holoviews/core/data/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def groupby(cls, dataset, dim_names, container_type, group_type, **kwargs):
group_kwargs['kdims'] = kdims
group_kwargs.update(kwargs)

drop_dim = len(group_kwargs['kdims']) != len(kdims)
drop_dim = any(d not in group_kwargs['kdims'] for d in kdims)

# Find all the keys along supplied dimensions
keys = [dataset.data[d.name] for d in dimensions]
Expand All @@ -206,7 +206,7 @@ def groupby(cls, dataset, dim_names, container_type, group_type, **kwargs):
group_data = {dataset.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:
elif not drop_dim:
for vdim in dataset.vdims:
group_data[vdim.name] = np.squeeze(group_data[vdim.name])
group_data = group_type(group_data, **group_kwargs)
Expand Down
5 changes: 3 additions & 2 deletions holoviews/core/data/iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def init(cls, eltype, data, kdims, vdims):

@classmethod
def validate(cls, dataset):
pass
if len(dataset.vdims) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always good to have some extra validation!

raise ValueError("Iris cubes do not support more than one value dimension")


@classmethod
Expand Down Expand Up @@ -187,7 +188,7 @@ def groupby(cls, dataset, dims, container_type=HoloMap, group_type=None, **kwarg
group_kwargs['kdims'] = slice_dims
group_kwargs.update(kwargs)

drop_dim = len(group_kwargs['kdims']) != len(slice_dims)
drop_dim = any(d not in group_kwargs['kdims'] for d in slice_dims)

unique_coords = product(*[cls.values(dataset, d, expanded=False)
for d in dims])
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def groupby(cls, dataset, dimensions, container_type, group_type, **kwargs):
kdims=element_dims)
group_kwargs.update(kwargs)

drop_dim = len(group_kwargs['kdims']) != len(element_dims)
drop_dim = any(d not in group_kwargs['kdims'] for d in element_dims)

# XArray 0.7.2 does not support multi-dimensional groupby
# Replace custom implementation when
Expand Down
22 changes: 22 additions & 0 deletions tests/testdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,22 @@ def test_dataset_groupby_drop_dims_dynamic(self):
partial = ds.to(Dataset, kdims=['x'], vdims=['Val'], groupby='y', dynamic=True)
self.assertEqual(partial[19]['Val'], array[:, -1, :].T.flatten())

def test_dataset_groupby_drop_dims_with_vdim(self):
array = np.random.rand(3, 20, 10)
ds = Dataset({'x': range(10), 'y': range(20), 'z': range(3), 'Val': array, 'Val2': array*2},
kdims=['x', 'y', 'z'], vdims=['Val', 'Val2'])
with DatatypeContext([self.datatype, 'columns', 'dataframe']):
partial = ds.to(Dataset, kdims=['Val'], vdims=['Val2'], groupby='y')
self.assertEqual(partial.last['Val'], array[:, -1, :].T.flatten())

def test_dataset_groupby_drop_dims_dynamic_with_vdim(self):
array = np.random.rand(3, 20, 10)
ds = Dataset({'x': range(10), 'y': range(20), 'z': range(3), 'Val': array, 'Val2': array*2},
kdims=['x', 'y', 'z'], vdims=['Val', 'Val2'])
with DatatypeContext([self.datatype, 'columns', 'dataframe']):
partial = ds.to(Dataset, kdims=['Val'], vdims=['Val2'], groupby='y', dynamic=True)
self.assertEqual(partial[19]['Val'], array[:, -1, :].T.flatten())


class IrisDatasetTest(GridDatasetTest):
"""
Expand Down Expand Up @@ -929,6 +945,12 @@ def test_dataset_sample_hm(self):
def test_dataset_sample_hm_alias(self):
raise SkipTest("Not supported")

def test_dataset_groupby_drop_dims_with_vdim(self):
raise SkipTest("Not supported")

def test_dataset_groupby_drop_dims_dynamic_with_vdim(self):
raise SkipTest("Not supported")


class XArrayDatasetTest(GridDatasetTest):
"""
Expand Down