Skip to content

Commit

Permalink
Merge ed51de7 into cf2fc33
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Feb 5, 2019
2 parents cf2fc33 + ed51de7 commit 37530ac
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
12 changes: 9 additions & 3 deletions holoviews/core/dimension.py
Expand Up @@ -1409,10 +1409,16 @@ def options(self, *args, **kwargs):

from ..util import opts
if options is None:
expanded = {}
expanded_backends = [({}, backend)]
elif isinstance(options, list): # List of Options objects
expanded_backends = opts._expand_by_backend(options, backend)
else:
expanded = opts._expand_options(options, backend)
return self.opts(expanded, backend=backend, clone=clone)
expanded_backends = [(opts._expand_options(options, backend), backend)]

obj = self
for backend, expanded in expanded_backends:
obj = obj.opts(expanded, backend=backend, clone=clone)
return obj


def _repr_mimebundle_(self, include=None, exclude=None):
Expand Down
6 changes: 4 additions & 2 deletions holoviews/core/options.py
Expand Up @@ -583,7 +583,8 @@ class Options(param.Parameterized):

_option_groups = ['style', 'plot', 'norm']

def __init__(self, key=None, allowed_keywords=[], merge_keywords=True, max_cycles=None, **kwargs):
def __init__(self, key=None, allowed_keywords=[], merge_keywords=True,
max_cycles=None, backend=None, **kwargs):

invalid_kws = []
for kwarg in sorted(kwargs.keys()):
Expand Down Expand Up @@ -612,6 +613,7 @@ def __init__(self, key=None, allowed_keywords=[], merge_keywords=True, max_cycle
else Keywords(allowed_keywords))
super(Options, self).__init__(allowed_keywords=allowed_keywords,
merge_keywords=merge_keywords, key=key)
self.backend = backend

def keywords_target(self, target):
"""
Expand Down Expand Up @@ -1932,7 +1934,7 @@ def set_options(cls, obj, options=None, backend=None, **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 ids to the objects
not_used = []
for (match_id, new_id) in id_mapping:
Expand Down
34 changes: 30 additions & 4 deletions holoviews/util/__init__.py
Expand Up @@ -83,7 +83,9 @@ class opts(param.ParameterizedFunction):
strict, invalid keywords prevent the options being applied.""")

def __call__(self, *args, **params):
if params and not args:
if not params and not args:
return Options()
elif params and not args:
return Options(**params)

if len(args) == 1:
Expand Down Expand Up @@ -117,13 +119,13 @@ def apply_groups(cls, obj, options=None, backend=None, clone=True, **kwargs):
simple format may be used, e.g.:
opts.apply_groups(obj, style={'cmap': 'viridis'},
plot={'show_title': False})
plot={'show_title': False})
If the object is nested the options must be qualified using
a type[.group][.label] specification, e.g.:
opts.apply_groups(obj, {'Image': {'plot': {'show_title': False},
'style': {'cmap': 'viridis}}})
'style': {'cmap': 'viridis}}})
If no opts are supplied all options on the object will be reset.
Expand Down Expand Up @@ -244,6 +246,30 @@ def defaults(cls, *options, **kwargs):
cls._linemagic(cls._expand_options(merge_options_to_dict(options)), backend=kwargs.get('backend'))


@classmethod
def _expand_by_backend(cls, options, backend):
"Given a list of Option objects, return a list of grouped backend"
groups = defaultdict(list)
used_fallback = False
for obj in options:
if obj is None: # Why are None's being supplied?
continue
elif obj.backend:
opts_backend = obj.backend
elif backend is None:
opts_backend = Store.current_backend
obj.backend= opts_backend
else:
opts_backend = backend
obj.backend = opts_backend
used_fallback = True
groups[opts_backend].append(obj)

if backend and not used_fallback:
cls.param.warning('Fallback backend specified but not used.')

return [(bk, cls._expand_options(o, bk)) for (bk, o) in groups.items()]

@classmethod
def _expand_options(cls, options, backend=None):
"""
Expand Down Expand Up @@ -410,7 +436,7 @@ def builder(cls, spec=None, **kws):
if reraise:
raise ValueError(prefix + msg)

return Options(spec, **kws)
return Options(spec, backend=backend, **kws)

filtered_keywords = [k for k in completions if k not in cls._no_completion]
kws = ', '.join('{opt}=None'.format(opt=opt) for opt in sorted(filtered_keywords))
Expand Down

0 comments on commit 37530ac

Please sign in to comment.