Skip to content

Commit

Permalink
Merge pull request #439 from ioam/propagate_id
Browse files Browse the repository at this point in the history
Dimensioned.clone always transfers id to new object
  • Loading branch information
jlstevens committed Feb 3, 2016
2 parents 2a748c2 + 6964e8c commit 50f2295
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def clone(self, data=None, shared_data=True, new_type=None, *args, **overrides):
params = {k: v for k, v in params.items()
if k in new_params}
settings = dict(params, **overrides)
if 'id' not in settings:
settings['id'] = self.id

if data is None and shared_data:
data = self.data
# Apply name mangling for __ attribute
Expand Down
19 changes: 16 additions & 3 deletions holoviews/core/ndmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def __init__(self, initial_items=None, group=None, label=None, **params):
super(UniformNdMapping, self).__init__(initial_items, **params)


def clone(self, data=None, shared_data=True, *args, **overrides):
def clone(self, data=None, shared_data=True, new_type=None, *args, **overrides):
"""
Returns a clone of the object with matching parameter values
containing the specified args and kwargs.
Expand All @@ -743,11 +743,24 @@ def clone(self, data=None, shared_data=True, *args, **overrides):
settings.pop('group')
if settings.get('label', None) != self._label:
settings.pop('label')
settings.update(overrides)
if new_type is None:
clone_type = self.__class__
else:
clone_type = new_type
new_params = new_type.params()
settings = {k: v for k, v in settings.items()
if k in new_params}
settings = dict(settings, **overrides)
if 'id' not in settings:
settings['id'] = self.id

if data is None and shared_data:
data = self.data
# Apply name mangling for __ attribute
pos_args = getattr(self, '_' + type(self).__name__ + '__pos_params', [])
with item_check(not shared_data and self._check_items):
return self.__class__(data, *args, **settings)
return clone_type(data, *args, **{k:v for k,v in settings.items()
if k not in pos_args})


@property
Expand Down

0 comments on commit 50f2295

Please sign in to comment.