Skip to content

Commit

Permalink
Fixed bug setting options when backends switched (#3323)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 20, 2018
1 parent 50ae8f0 commit d6374ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
23 changes: 9 additions & 14 deletions holoviews/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,14 +1793,19 @@ def update_backends(cls, id_mapping, custom_trees, backend=None):
supplied trees and update the keys in the remaining backends to
stay linked with the current object.
"""
backend = Store.current_backend if backend is None else backend
# Update the custom option entries for the current backend
Store.custom_options(backend=backend).update(custom_trees)
# Update the entries in other backends so the ids match correctly
for backend in [k for k in Store.renderers.keys() if k != Store.current_backend]:

# Propagate option ids for non-selected backends
for b in Store.loaded_backends():
if b == backend:
continue
backend_trees = Store._custom_options[b]
for (old_id, new_id) in id_mapping:
tree = Store._custom_options[backend].pop(old_id, None)
tree = backend_trees.get(old_id, None)
if tree is not None:
Store._custom_options[backend][new_id] = tree
backend_trees[new_id] = tree


@classmethod
Expand Down Expand Up @@ -1847,21 +1852,11 @@ def set_options(cls, obj, options=None, backend=None, **kwargs):

# {'Image.Channel:{'plot': Options(size=50),
# 'style': Options('style', cmap='Blues')]}
backend = Store.current_backend if backend is None else backend
options = cls.merge_options(Store.options(backend=backend).groups.keys(), options, **kwargs)
spec, compositor_applied = cls.expand_compositor_keys(options)
custom_trees, id_mapping = cls.create_custom_trees(obj, spec)
cls.update_backends(id_mapping, custom_trees, backend=backend)

# Propagate option ids for non-selected backends
for b in Store.loaded_backends():
if b == backend:
continue
backend_trees = Store.custom_options(backend=b)
btrees = {v: backend_trees[k] for k, v in id_mapping
if k in backend_trees}
cls.update_backends(id_mapping, btrees, backend=b)

# Propagate ids to the objects
for (match_id, new_id) in id_mapping:
cls.propagate_ids(obj, match_id, new_id, compositor_applied+list(spec.keys()), backend=backend)
Expand Down
11 changes: 11 additions & 0 deletions holoviews/tests/core/testdimensioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,14 @@ def test_apply_options_explicit_backend_persists_other_backend_inverted(self):
assert plot_opts.options == {'plot_opt1': 'B'}
style_opts = Store.lookup_options('backend_2', obj, 'style')
assert style_opts.options == {'style_opt1': 'A'}

def test_apply_options_when_backend_switched(self):
obj = TestObj([])
Store.current_backend = 'backend_2'
obj.opts(style_opt1='A', plot_opt1='B')
Store.current_backend = 'backend_1'
obj.opts(style_opt1='C', plot_opt1='D', backend='backend_2')
plot_opts = Store.lookup_options('backend_2', obj, 'plot')
assert plot_opts.options == {'plot_opt1': 'D'}
style_opts = Store.lookup_options('backend_2', obj, 'style')
assert style_opts.options == {'style_opt1': 'C'}

0 comments on commit d6374ee

Please sign in to comment.