Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
var_tuples.append((da.name, da.attrs))
labels = {}
units = {}
for var_name, var_attrs in var_tuples:
if var_name is None:
var_name = 'value'
if 'long_name' in var_attrs:
labels[var_name] = var_attrs['long_name']
if 'units' in var_attrs:
units[var_name] = var_attrs['units']
self._redim = self._merge_redim(labels, 'label')
self._redim = self._merge_redim(units, 'unit')
except Exception as e:
if attr_labels is True:
param.main.warning('Unable to auto label using xarray attrs '
'because {e}'.format(e=e))
def _verify_task_times(self, task, times, strict=False):
"""
Checks that a given task that is scheduled to be run at
certain times will actually be executed. The strict flag
determines whether to simply warn or raise an Exception.
"""
if task.times:
unsatisfied = set(task.times) - set(list(times))
if unsatisfied:
msg = "Task %r has been requested for times %s, " \
"not scheduled for collection." % (task, list(unsatisfied))
if unsatisfied:
if strict: raise Exception(msg)
else: param.main.warning(msg)
def trigger(cls, streams):
"""
Given a list of streams, collect all the stream parameters into
a dictionary and pass it to the union set of subscribers.
Passing multiple streams at once to trigger can be useful when a
subscriber may be set multiple times across streams but only
needs to be called once.
"""
# Union of stream contents
items = [stream.contents.items() for stream in streams]
union = [kv for kvs in items for kv in kvs]
klist = [k for k, _ in union]
clashes = set([k for k in klist if klist.count(k) > 1])
if clashes:
param.main.warning('Parameter name clashes for keys: %r' % clashes)
# Group subscribers by precedence while keeping the ordering
# within each group
subscriber_precedence = defaultdict(list)
for stream in streams:
for precedence, subscriber in stream._subscribers:
subscriber_precedence[precedence].append(subscriber)
sorted_subscribers = sorted(subscriber_precedence.items(), key=lambda x: x[0])
subscribers = util.unique_iterator([s for _, subscribers in sorted_subscribers
for s in subscribers])
with triggering_streams(streams):
for subscriber in subscribers:
subscriber(**dict(union))
for stream in streams:
def _process_plot(self):
kind = self.kind
options = Store.options(backend='bokeh')
elname = self._kind_mapping[kind].__name__
plot_opts = options[elname].groups['plot'].options if elname in options else {}
if kind.startswith('bar'):
plot_opts['stacked'] = self.stacked
if kind == 'hist':
if self.stacked:
param.main.warning('Stacking for histograms is not yet implemented in '
'holoviews. Use bar plots if stacking is required.')
return plot_opts
def _yield_abbreviations_for_parameter(parameter, kwargs):
"""Get an abbreviation for a function parameter."""
name = parameter.name
kind = parameter.kind
ann = parameter.annotation
default = parameter.default
not_found = (name, empty, empty)
if kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.KEYWORD_ONLY):
if name in kwargs:
value = kwargs.pop(name)
elif ann is not empty:
param.main.warning("Using function annotations to implicitly specify interactive controls is deprecated. "
"Use an explicit keyword argument for the parameter instead.", DeprecationWarning)
value = ann
elif default is not empty:
value = default
if isinstance(value, (Iterable, Mapping)):
value = fixed(value)
else:
yield not_found
yield (name, value, default)
elif kind == Parameter.VAR_KEYWORD:
# In this case name=kwargs and we yield the items in kwargs with their keys.
for k, v in kwargs.copy().items():
kwargs.pop(k)
yield k, v, empty
from .dictionary import DictInterface
from .grid import GridInterface
from .multipath import MultiInterface # noqa (API import)
from .image import ImageInterface # noqa (API import)
datatypes = ['array', 'dictionary', 'grid']
try:
import pandas as pd # noqa (Availability import)
from .pandas import PandasInterface
datatypes = ['array', 'dataframe', 'dictionary', 'grid', 'ndelement']
DFColumns = PandasInterface
except ImportError:
pass
except Exception as e:
param.main.warning('Pandas interface failed to import with '
'following error: %s' % e)
try:
import iris # noqa (Availability import)
from .iris import CubeInterface # noqa (Conditional API import)
datatypes.append('cube')
except ImportError:
pass
except Exception as e:
param.main.warning('Iris interface failed to import with '
'following error: %s' % e)
try:
import xarray # noqa (Availability import)
from .xarray import XArrayInterface # noqa (Conditional API import)
datatypes.append('xarray')
def _repr_mimebundle_(self, include=None, exclude=None):
loaded = panel_extension._loaded
if not loaded and 'holoviews' in sys.modules:
import holoviews as hv
loaded = hv.extension._loaded
if not loaded:
param.main.warning('Displaying Panel objects in the notebook '
'requires the panel extension to be loaded. '
'Ensure you run pn.extension() before '
'displaying objects in the notebook.')
return None
try:
assert get_ipython().kernel is not None # noqa
state._comm_manager = _JupyterCommManager
except Exception:
pass
from IPython.display import display
doc = _Document()
comm = state._comm_manager.get_server_comm()
self._init_doc(doc, comm, notebook=True)
def _verify_task_times(self, task, times, strict=False):
"""
Checks that a given task that is scheduled to be run at
certain times will actually be executed. The strict flag
determines whether to simply warn or raise an Exception.
"""
if task.times:
unsatisfied = set(task.times) - set(list(times))
if unsatisfied:
msg = "Task %r has been requested for times %s, " \
"not scheduled for collection." % (task, list(unsatisfied))
if unsatisfied:
if strict: raise Exception(msg)
else: param.main.warning(msg)
def _apply_layers(self, obj):
if self.coastline:
import geoviews as gv
coastline = gv.feature.coastline()
if self.coastline in ['10m', '50m', '110m']:
coastline = coastline.opts(scale=self.coastline)
elif self.coastline is not True:
param.main.warning("coastline scale of %s not recognized, "
"must be one of '10m', '50m' or '110m'." %
self.coastline)
obj = obj * coastline
if self.tiles:
tile_source = 'EsriImagery' if self.tiles == 'ESRI' else self.tiles
warning = ("%s tiles not recognized, must be one of: %s or a tile object" %
(tile_source, sorted(hv.element.tile_sources)))
if tile_source is True:
tiles = hv.element.tiles.Wikipedia()
elif tile_source in hv.element.tile_sources.keys():
tiles = hv.element.tile_sources[tile_source]()
elif tile_source in hv.element.tile_sources.values():
tiles = tile_source()
elif isinstance(tile_source, hv.element.tiles.Tiles):
tiles = tile_source
elif self.geo: