diff --git a/holoviews/core/dimension.py b/holoviews/core/dimension.py index 3b77aebd7b..40f8307559 100644 --- a/holoviews/core/dimension.py +++ b/holoviews/core/dimension.py @@ -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) + 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) diff --git a/tests/testdimensions.py b/tests/testdimensions.py index 4aebfa8889..2dfe07e3d0 100644 --- a/tests/testdimensions.py +++ b/tests/testdimensions.py @@ -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'])