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

Allow ElementOperation to process NdLayout types #1228

Merged
merged 2 commits into from
Mar 24, 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
7 changes: 3 additions & 4 deletions holoviews/core/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pass

from .dimension import ViewableElement
from .element import Element, HoloMap, GridSpace, Collator
from .element import Element, HoloMap, GridSpace, NdLayout, Collator
from .layout import Layout
from .overlay import NdOverlay, Overlay
from .spaces import DynamicMap, Callable
Expand Down Expand Up @@ -132,12 +132,11 @@ def __call__(self, element, **params):
isinstance(element, DynamicMap))
or self.p.dynamic is True)

if isinstance(element, GridSpace):
if isinstance(element, (GridSpace, NdLayout)):
# Initialize an empty axis layout
grid_data = ((pos, self(cell, **params))
for pos, cell in element.items())
processed = GridSpace(grid_data, label=element.label,
kdims=element.kdims)
processed = element.clone(grid_data)
elif dynamic:
from ..util import Dynamic
streams = getattr(self.p, 'streams', [])
Expand Down
18 changes: 16 additions & 2 deletions tests/testoperation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from holoviews import (HoloMap, NdOverlay, Image, Contours, Polygons, Points,
Histogram, Curve)
from holoviews import (HoloMap, NdOverlay, NdLayout, GridSpace, Image,
Contours, Polygons, Points, Histogram, Curve)
from holoviews.element.comparison import ComparisonTestCase
from holoviews.operation.element import (operation, transform, threshold,
gradient, contours, histogram,
Expand All @@ -18,6 +18,20 @@ def test_operation_element(self):
op_img = operation(img, op=lambda x, k: x.clone(x.data*2))
self.assertEqual(op_img, img.clone(img.data*2, group='Operation'))

def test_operation_ndlayout(self):
ndlayout = NdLayout({i: Image(np.random.rand(10, 10)) for i in range(10)})
op_ndlayout = operation(ndlayout, op=lambda x, k: x.clone(x.data*2))
doubled = ndlayout.clone({k: v.clone(v.data*2, group='Operation')
for k, v in ndlayout.items()})
self.assertEqual(op_ndlayout, doubled)

def test_operation_grid(self):
grid = GridSpace({i: Image(np.random.rand(10, 10)) for i in range(10)}, kdims=['X'])
op_grid = operation(grid, op=lambda x, k: x.clone(x.data*2))
doubled = grid.clone({k: v.clone(v.data*2, group='Operation')
for k, v in grid.items()})
self.assertEqual(op_grid, doubled)

def test_operation_holomap(self):
hmap = HoloMap({1: Image(np.random.rand(10, 10))})
op_hmap = operation(hmap, op=lambda x, k: x.clone(x.data*2))
Expand Down