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

Raise KeyError when attempting to slice Layout #1295

Merged
merged 3 commits into from
Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions holoviews/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ def __getitem__(self, key):
if key < len(self):
return self.data.values()[key]
raise KeyError("Element out of range.")
elif isinstance(key, slice):
raise KeyError("A Layout may not be sliced, ensure that you "
"are slicing on a leaf (i.e. not a branch) of the Layout.")
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe 'leaf node' or 'leaf item'?

if len(key) == 2 and not any([isinstance(k, str) for k in key]):
if key == (slice(None), slice(None)): return self
row, col = key
Expand Down
14 changes: 13 additions & 1 deletion tests/testannotations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from holoviews import Image, HLine, VLine
from holoviews import Image, HLine, VLine, Text, Arrow, Annotation
from holoviews.element.comparison import ComparisonTestCase

class AnnotationTests(ComparisonTestCase):
Expand All @@ -18,3 +18,15 @@ def test_vline_dimension_values(self):
hline = VLine(0)
self.assertEqual(hline.range(0), (0, 0))
self.assertEqual(hline.range(1), (None, None))

def test_deep_clone_map_select_redim(self):
annotations = (Text(0, 0, 'A') + Arrow(0, 0) + HLine(0) + VLine(0))
selected = annotations.select(x=(0, 5))
redimmed = selected.redim(x='z')
relabelled = redimmed.relabel(label='foo', depth=5)
mapped = relabelled.map(lambda x: x.clone(group='bar'), Annotation)
kwargs = dict(label='foo', group='bar', extents=(0, None, 5, None), kdims=['z', 'y'])
self.assertEqual(mapped.Text.I, Text(0, 0, 'A', **kwargs))
self.assertEqual(mapped.Arrow.I, Arrow(0, 0, **kwargs))
self.assertEqual(mapped.HLine.I, HLine(0, **kwargs))
self.assertEqual(mapped.VLine.I, VLine(0, **kwargs))