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 redim.label if no custom label set #1541

Merged
merged 3 commits into from Jun 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions holoviews/core/dimension.py
Expand Up @@ -158,6 +158,13 @@ def value_format(self, specs=None, **values):
def range(self, specs=None, **values):
return self._redim('range', specs, **values)

def label(self, specs=None, **values):
for k, v in values.items():
dim = self.parent.get_dimension(k)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like None is returned if there is no match for dim? In which case a suitable exception/warning should be given if dim==None.

Copy link
Member Author

Choose a reason for hiding this comment

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

redim doesn't validate Dimensions so you can apply it nested datastructures. That said I'd possibly be open to tightening that up when explicit specs are supplied, not in this PR though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, thanks for the reminder. It is annoying but I can't see a way around that issue right now...

if dim and dim.name != dim.label and dim.name != v:
raise ValueError('Cannot override an existing Dimension label')
return self._redim('label', specs, **values)

def soft_range(self, specs=None, **values):
return self._redim('soft_range', specs, **values)

Expand Down
10 changes: 10 additions & 0 deletions tests/testdimensions.py
Expand Up @@ -245,6 +245,16 @@ def test_dimensioned_redim_string(self):
redimensioned = dimensioned.clone(kdims=['Test'])
self.assertEqual(redimensioned, dimensioned.redim(x='Test'))

def test_dimensioned_redim_dict_label(self):
dimensioned = Dimensioned('Arbitrary Data', kdims=['x'])
redimensioned = dimensioned.clone(kdims=[('x', 'Test')])
self.assertEqual(redimensioned, dimensioned.redim.label(x='Test'))

def test_dimensioned_redim_dict_label_existing_error(self):
dimensioned = Dimensioned('Arbitrary Data', kdims=[('x', 'Test1')])
with self.assertRaisesRegexp(ValueError, 'Cannot override an existing Dimension label'):
dimensioned.redim.label(x='Test2')

def test_dimensioned_redim_dimension(self):
dimensioned = Dimensioned('Arbitrary Data', kdims=['x'])
redimensioned = dimensioned.clone(kdims=['Test'])
Expand Down