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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+28 −5
Diff settings

Always

Just for now

Copy path View file
@@ -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]
@@ -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)
Copy path View file
@@ -117,7 +117,8 @@ def init(cls, eltype, data, kdims, vdims):

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

This comment has been minimized.

Copy link
@jlstevens

jlstevens Mar 21, 2017

Contributor

Always good to have some extra validation!

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


@classmethod
@@ -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])
Copy path View file
@@ -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
Copy path View file
@@ -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):
"""
@@ -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):
"""
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.