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

Always

Just for now

Copy path View file
@@ -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)

This comment has been minimized.

Copy link
@jlstevens

jlstevens Jun 14, 2017

Contributor

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.

This comment has been minimized.

Copy link
@philippjfr

philippjfr Jun 14, 2017

Author Contributor

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.

This comment has been minimized.

Copy link
@jlstevens

jlstevens Jun 14, 2017

Contributor

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)

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