Skip to content
Permalink
Browse files

Merge db1e36c into 80dd30e

  • Loading branch information...
jlstevens committed Dec 7, 2018
2 parents 80dd30e + db1e36c commit ef54f865c65963788d69c4d4454b01520269fd1a
Showing with 296 additions and 130 deletions.
  1. +47 −66 holoviews/core/dimension.py
  2. +95 −45 holoviews/core/spaces.py
  3. +25 −0 holoviews/core/util.py
  4. +129 −19 holoviews/util/__init__.py
@@ -17,7 +17,7 @@
import numpy as np

from . import util
from .options import Store, StoreOptions
from .options import Store
from .pprint import PrettyPrinter
from .tree import AttrTree
from .util import basestring, OrderedDict, bytes_to_unicode, unicode
@@ -1311,91 +1311,69 @@ def __call__(self, options=None, **kwargs):

return self.opts(options, **kwargs)

def opts(self, options=None, backend=None, clone=True, **kwargs):
"""Applies nested options definition

def opts(self, *args, **kwargs):
"""Applies nested options definition.
Applies options on an object or nested group of objects in a
by options group returning a new object with the options
applied. If the options are to be set directly on the object a
simple format may be used, e.g.:
flat format. Unlike the .options method, .opts modifies the
options inplace by default. If the options are to be set
directly on the object a simple format may be used, e.g.:
obj.opts(style={'cmap': 'viridis'}, plot={'show_title': False})
obj.opts(cmap='viridis', show_title=False)
If the object is nested the options must be qualified using
a type[.group][.label] specification, e.g.:
obj.opts({'Image': {'plot': {'show_title': False},
'style': {'cmap': 'viridis}}})
obj.opts('Image', cmap='viridis', show_title=False)
or using:
If no opts are supplied all options on the object will be reset.
obj.opts({'Image': dict(cmap='viridis', show_title=False)})
Args:
options (dict): Options specification
Options specification should be indexed by
type[.group][.label] or option type ('plot', 'style',
'norm').
*args: Sets of options to apply to object
Supports a number of formats including lists of Options
objects, a type[.group][.label] followed by a set of
keyword options to apply and a dictionary indexed by
type[.group][.label] specs.
backend (optional): Backend to apply options to
Defaults to current selected backend
clone (bool, optional): Whether to clone object
Options can be applied inplace with clone=False
**kwargs: Keywords of options by type
Applies options directly to the object by type
(e.g. 'plot', 'style', 'norm') specified as
dictionaries.
**kwargs: Keywords of options
Set of options to apply to the object
For backwards compatibility, this method also supports the
option group semantics now offered by the hv.opts.apply_groups
utility. This usage will be deprecated and for more
information see the apply_options_type docstring.
Returns:
Returns the cloned object with the options applied
Returns the object or a clone with the options applied
"""
backend = backend or Store.current_backend
if isinstance(options, basestring):
from ..util.parser import OptsSpec
try:
options = OptsSpec.parse(options)
except SyntaxError:
options = OptsSpec.parse(
'{clsname} {options}'.format(clsname=self.__class__.__name__,
options=options))

backend_options = Store.options(backend=backend)
groups = set(backend_options.groups.keys())
if kwargs and set(kwargs) <= groups:
if not all(isinstance(v, dict) for v in kwargs.values()):
raise Exception("The %s options must be specified using dictionary groups" %
','.join(repr(k) for k in kwargs.keys()))

# Check whether the user is specifying targets (such as 'Image.Foo')
entries = backend_options.children
targets = [k.split('.')[0] in entries for grp in kwargs.values() for k in grp]
if any(targets) and not all(targets):
raise Exception("Cannot mix target specification keys such as 'Image' with non-target keywords.")
elif not any(targets):
# Not targets specified - add current object as target
sanitized_group = util.group_sanitizer(self.group)
if self.label:
identifier = ('%s.%s.%s' % (
self.__class__.__name__, sanitized_group,
util.label_sanitizer(self.label)))
elif sanitized_group != self.__class__.__name__:
identifier = '%s.%s' % (self.__class__.__name__, sanitized_group)
else:
identifier = self.__class__.__name__
apply_groups, options = util.deprecated_opts_signature(args, kwargs)

kwargs = {k:{identifier:v} for k,v in kwargs.items()}
# By default do not clone in .opts method
clone = kwargs.pop('clone', None)

obj = self
if options is None and kwargs == {}:
if clone:
obj = self.map(lambda x: x.clone(id=None))
else:
self.map(lambda x: setattr(x, 'id', None))
elif clone:
obj = self.map(lambda x: x.clone(id=x.id))
StoreOptions.set_options(obj, options, backend=backend, **kwargs)
return obj
if apply_groups and util.config.future_deprecations:
msg = ("Calling the .opts method with options broken down by options "
"group (i.e. separate plot, style and norm groups) is deprecated. "
"Use the .options method converting to the simplified format "
"instead or use hv.opts.apply_groups for backward compatibility.")
param.main.warning(msg)
if apply_groups:
from ..util import opts
kwargs['clone'] = True if clone is None else clone
return opts.apply_groups(self, options=options, **kwargs)

kwargs['clone'] = False if clone is None else clone
return self.options(*args, **kwargs)


def options(self, *args, **kwargs):
"""Applies simplified option definition
"""Applies simplified option definition returning a new object.
Applies options on an object or nested group of objects in a
flat format returning a new object with the options
@@ -1413,6 +1391,9 @@ def options(self, *args, **kwargs):
obj.options({'Image': dict(cmap='viridis', show_title=False)})
Identical to the .opts method but returns a clone of the object
by default.
Args:
*args: Sets of options to apply to object
Supports a number of formats including lists of Options
@@ -1456,8 +1437,8 @@ def options(self, *args, **kwargs):
if options is None:
expanded = {}
else:
expanded = opts.expand_options(options, backend)
return self.opts(expanded, backend, clone)
expanded = opts._expand_options(options, backend)
return self.opts(expanded, backend=backend, clone=clone)


def _repr_mimebundle_(self, include=None, exclude=None):
@@ -95,36 +95,67 @@ def layout(self, dimensions=None, **kwargs):
return self.groupby(dimensions, container_type=NdLayout, **kwargs)


def opts(self, options=None, backend=None, clone=True, **kwargs):
"""
Applies options on an object or nested group of objects in a
by options group returning a new object with the options
applied. If the options are to be set directly on the object a
simple format may be used, e.g.:
def opts(self, *args, **kwargs):
"""Applies simplified option definition
Applies options defined in a flat format to the objects in the
HoloMap. Unlike the .options method .opts, modifies the
options inplace by default. If the options are to be set
directly on the objects in the HoloMap a simple format may be
used, e.g.:
obj.opts(style={'cmap': 'viridis'}, plot={'show_title': False})
obj.opts(cmap='viridis', show_title=False)
If the object is nested the options must be qualified using
a type[.group][.label] specification, e.g.:
obj.opts({'Image': {'plot': {'show_title': False},
'style': {'cmap': 'viridis}}})
obj.opts('Image', cmap='viridis', show_title=False)
or using:
obj.opts({'Image': dict(cmap='viridis', show_title=False)})
Args:
*args: Sets of options to apply to object
Supports a number of formats including lists of Options
objects, a type[.group][.label] followed by a set of
keyword options to apply and a dictionary indexed by
type[.group][.label] specs.
backend (optional): Backend to apply options to
Defaults to current selected backend
clone (bool, optional): Whether to clone object
Options can be applied inplace with clone=False
**kwargs: Keywords of options
Set of options to apply to the object
For backwards compatibility, this method also supports the
option group semantics now offered by the hv.opts.apply_groups
utility. This usage will be deprecated and for more
information see the apply_options_type docstring.
If no opts are supplied all options on the object will be reset.
Disabling clone will modify the object inplace.
Returns:
Returns the object or a clone with the options applied
"""
data = OrderedDict([(k, v.opts(options, backend, clone, **kwargs))
clone = kwargs.pop('clone', None)
apply_groups, options = util.deprecated_opts_signature(args, kwargs)
data = OrderedDict([(k, v.opts(*args, **dict(**kwargs, options=options)))
for k, v in self.data.items()])
return self.clone(data)

# By default do not clone in .opts method
if (apply_groups if clone is None else clone):
return self.clone(data)
else:
self.data = data
return self


def options(self, *args, **kwargs):
"""Applies simplified option definition
"""Applies simplified option definition returning a new object
Applies options on an object or nested group of objects in a
flat format returning a new object with the options
applied. If the options are to be set directly on the object a
simple format may be used, e.g.:
Applies options defined in a flat format to the objects
returned by the DynamicMap. If the options are to be set
directly on the objects in the HoloMap a simple format may be
used, e.g.:
obj.options(cmap='viridis', show_title=False)
@@ -1097,57 +1128,76 @@ def _execute_callback(self, *args):
return self._style(retval)


def opts(self, options=None, backend=None, clone=True, **kwargs):
"""Applies nested options definition
def opts(self, *args, **kwargs):
"""Applies simplified options definition.
Applies options on an object or nested group of objects in a
by options group returning a new object with the options
applied. If the options are to be set directly on the object a
Applies options defined in a flat format to the objects
returned by the DynamicMap. Unlike the .options method, .opts
modifies the options inplace by default. If the options are to
be set directly on the objects returned by the DynamicMap a
simple format may be used, e.g.:
obj.opts(style={'cmap': 'viridis'}, plot={'show_title': False})
obj.opts(cmap='viridis', show_title=False)
If the object is nested the options must be qualified using
a type[.group][.label] specification, e.g.:
obj.opts({'Image': {'plot': {'show_title': False},
'style': {'cmap': 'viridis}}})
obj.opts('Image', cmap='viridis', show_title=False)
or using:
If no opts are supplied all options on the object will be reset.
obj.opts({'Image': dict(cmap='viridis', show_title=False)})
Args:
options (dict): Options specification
Options specification should be indexed by
type[.group][.label] or option type ('plot', 'style',
'norm').
*args: Sets of options to apply to object
Supports a number of formats including lists of Options
objects, a type[.group][.label] followed by a set of
keyword options to apply and a dictionary indexed by
type[.group][.label] specs.
backend (optional): Backend to apply options to
Defaults to current selected backend
clone (bool, optional): Whether to clone object
Options can be applied inplace with clone=False
**kwargs: Keywords of options by type
Applies options directly to the object by type
(e.g. 'plot', 'style', 'norm') specified as
dictionaries.
**kwargs: Keywords of options
Set of options to apply to the object
For backwards compatibility, this method also supports the
option group semantics now offered by the hv.opts.apply_groups
utility. This usage will be deprecated and for more
information see the apply_options_type docstring.
Returns:
Returns the cloned object with the options applied
Returns the object or a clone with the options applied
"""
from ..util import Dynamic
dmap = Dynamic(self, operation=lambda obj, **dynkwargs: obj.opts(options, backend,
clone, **kwargs),

clone = kwargs.pop('clone', None)
apply_groups, options = util.deprecated_opts_signature(args, kwargs)
kwargs['options'] = options
# By default do not clone in .opts method
clone = (apply_groups if clone is None else clone)

obj = self if clone else self.clone()
dmap = Dynamic(obj, operation=lambda obj, **dynkwargs: obj.opts(*args, **kwargs),
streams=self.streams, link_inputs=True)
dmap.data = OrderedDict([(k, v.opts(options, **kwargs))
for k, v in self.data.items()])
if not clone:
with util.disable_constant(self):
self.callback = dmap.callback
self.callback.inputs[:] = [obj]
obj.callback.inputs[:] = []
dmap = self
dmap.data = OrderedDict([(k, v.opts(*args, **kwargs))
for k, v in self.data.items()])
return dmap


def options(self, *args, **kwargs):
"""Applies simplified option definition
"""Applies simplified option definition returning a new object.
Applies options on an object or nested group of objects in a
flat format returning a new object with the options
applied. If the options are to be set directly on the object a
simple format may be used, e.g.:
Applies options defined in a flat format to the objects
returned by the DynamicMap. If the options are to be set
directly on the objects returned by the DynamicMap a simple
format may be used, e.g.:
obj.options(cmap='viridis', show_title=False)
@@ -224,6 +224,31 @@ def merge_options_to_dict(options):
return merged_options


def deprecated_opts_signature(args, kwargs):
"""
Utility to help with the deprecation of the old .opts method signature
Returns whether opts.apply_groups should be used (as a bool) and the
corresponding options.
"""
signature = ['plot','style', 'norm', 'clone', 'backend']
apply_groups = False
options = None
if len(args) > 0 and isinstance(args[0], dict):
apply_groups = True
options = args[0]
elif kwargs and set(kwargs.keys()).issubset(set(signature)):
apply_groups = True
options = None
elif 'options' in kwargs:
apply_groups = True
options = kwargs.pop('options')
elif not args and not kwargs:
apply_groups = True
options = None
return apply_groups, options


class periodic(Thread):
"""
Run a callback count times with a given period without blocking.

0 comments on commit ef54f86

Please sign in to comment.
You can’t perform that action at this time.