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

Fixed bug adding dimension to XArrayInterface #2761

Merged
merged 2 commits into from
Jun 4, 2018
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
5 changes: 3 additions & 2 deletions holoviews/core/data/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,9 @@ def add_dimension(cls, dataset, dimension, dim_pos, values, vdim):
if not vdim:
raise Exception("Cannot add key dimension to a dense representation.")
dim = dimension.name if isinstance(dimension, Dimension) else dimension
arr = xr.DataArray(values, coords=dataset.data.coords, name=dim,
dims=dataset.data.indexes)
coords = {d.name: cls.coords(dataset, d.name) for d in dataset.kdims}
arr = xr.DataArray(values, coords=coords, name=dim,
dims=tuple(d.name for d in dataset.kdims[::-1]))
return dataset.data.assign(**{dim: arr})


Expand Down
7 changes: 7 additions & 0 deletions tests/core/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,10 @@ def test_sample_2d(self):
values = np.sin(XS)
sampled = Dataset((xs, ys, values), ['x', 'y'], 'z').sample(y=0)
self.assertEqual(sampled, Curve((xs, values[0]), vdims='z'))

def test_aggregate_2d_with_spreadfn(self):
array = np.random.rand(10, 5)
ds = Dataset((range(5), range(10), array), ['x', 'y'], 'z')
agg = ds.aggregate('x', np.mean, np.std)
example = Dataset((range(5), array.mean(axis=0), array.std(axis=0)), 'x', ['z', 'z_std'])
self.assertEqual(agg, example)
3 changes: 3 additions & 0 deletions tests/core/data/testirisinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def test_dataset_2D_aggregate_partial_hm(self):
def test_dataset_2D_aggregate_partial_hm_alias(self):
raise SkipTest("Not supported")

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

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

Expand Down