Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class OneOfFilter(BaseObject):
"""Wrapper for Vega-Lite OneOfFilter definition.
Attributes
----------
field: Unicode
Field to be filtered.
oneOf: List(Union(Unicode, CFloat, Bool, DateTime))
A set of values that the `field`'s value should be a member of, for a data item included in the filtered data.
timeUnit: TimeUnit
time unit for the field to be filtered.
"""
field = T.Unicode(allow_none=True, default_value=None, help="""Field to be filtered.""")
oneOf = T.List(T.Union([T.Unicode(allow_none=True, default_value=None), T.CFloat(allow_none=True, default_value=None), T.Bool(allow_none=True, default_value=None), T.Instance(DateTime, allow_none=True, default_value=None)]), allow_none=True, default_value=None, help="""A set of values that the `field`'s value should be a member of, for a data item included in the filtered data.""")
timeUnit = TimeUnit(allow_none=True, default_value=None, help="""time unit for the field to be filtered.""")
def __init__(self, field=None, oneOf=None, timeUnit=None, **kwargs):
kwds = dict(field=field, oneOf=oneOf, timeUnit=timeUnit)
kwargs.update({k:v for k, v in kwds.items() if v is not None})
super(OneOfFilter, self).__init__(**kwargs)
timeUnit: TimeUnit
Time unit for a `temporal` field .
title: Unicode
Title for axis or legend.
type: Type
The encoded field's type of measurement.
value: Union(CFloat, Unicode, Bool)
A constant value in visual domain.
"""
aggregate = AggregateOp(allow_none=True, default_value=None, help="""Aggregation function for the field .""")
bin = T.Union([T.Bool(allow_none=True, default_value=None), T.Instance(Bin, allow_none=True, default_value=None)])
field = T.Unicode(allow_none=True, default_value=None, help="""Name of the field from which to pull a data value.""")
legend = T.Instance(Legend, allow_none=True, default_value=None)
scale = T.Instance(Scale, allow_none=True, default_value=None)
sort = T.Union([T.Instance(SortField, allow_none=True, default_value=None), SortOrder(allow_none=True, default_value=None)])
timeUnit = TimeUnit(allow_none=True, default_value=None, help="""Time unit for a `temporal` field .""")
title = T.Unicode(allow_none=True, default_value=None, help="""Title for axis or legend.""")
type = Type(allow_none=True, default_value=None, help="""The encoded field's type of measurement.""")
value = T.Union([T.CFloat(allow_none=True, default_value=None), T.Unicode(allow_none=True, default_value=None), T.Bool(allow_none=True, default_value=None)])
def __init__(self, aggregate=None, bin=None, field=None, legend=None, scale=None, sort=None, timeUnit=None, title=None, type=None, value=None, **kwargs):
kwds = dict(aggregate=aggregate, bin=bin, field=field, legend=legend, scale=scale, sort=sort, timeUnit=timeUnit, title=title, type=type, value=value)
kwargs.update({k:v for k, v in kwds.items() if v is not None})
super(ChannelDefWithLegend, self).__init__(**kwargs)
* get coordinates by dimension name: ``coords['lat']``
* get iterable dimension keys and coordinates values: ``coords.keys()``, ``coords.values()``
* loop through dimensions: ``for dim in coords: ...``
Parameters
----------
dims
Tuple of dimension names, potentially stacked.
udims
Tuple of individual dimension names, always unstacked.
"""
crs = tl.Unicode(read_only=True, allow_none=True)
_coords = OrderedDictTrait(trait=tl.Instance(BaseCoordinates), default_value=OrderedDict())
def __init__(self, coords, dims=None, crs=None, validate_crs=True):
"""
Create multidimensional coordinates.
Arguments
---------
coords : list
List of coordinate values for each dimension. Valid coordinate values:
* single coordinate value (number, datetime64, or str)
* array of coordinate values
* list of stacked coordinate values
* :class:`Coordinates1d` or :class:`StackedCoordinates` object
dims : list of str, optional
List of dimension names. Optional if all items in ``coords`` are named. Valid names are
@default('stdout')
def _default_stdout(self):
return OutStream(self.session, self.iopub_thread, u'stdout')
@default('stderr')
def _default_stderr(self):
return OutStream(self.session, self.iopub_thread, u'stderr')
#-----------------------------------------------------------------------------
# Interactive shell subclass
#-----------------------------------------------------------------------------
class InProcessInteractiveShell(ZMQInteractiveShell):
kernel = Instance('yap_kernel.inprocess.ipkernel.InProcessKernel',
allow_none=True)
#-------------------------------------------------------------------------
# InteractiveShell interface
#-------------------------------------------------------------------------
def enable_gui(self, gui=None):
"""Enable GUI integration for the kernel."""
from yap_kernel.eventloops import enable_gui
if not gui:
gui = self.kernel.gui
enable_gui(gui, kernel=self.kernel)
self.active_eventloop = gui
def enable_matplotlib(self, gui=None):
An object describing the data source.
description: Unicode
An optional description of this mark for commenting purpose.
height: CFloat
layers: List(UnitSpec)
Unit specs that will be layered.
name: Unicode
Name of the visualization for later reference.
transform: Transform
An object describing filter and new field calculation.
width: CFloat
"""
config = T.Instance(Config, allow_none=True, default_value=None, help="""Configuration object.""")
data = T.Instance(Data, allow_none=True, default_value=None, help="""An object describing the data source.""")
description = T.Unicode(allow_none=True, default_value=None, help="""An optional description of this mark for commenting purpose.""")
height = T.CFloat(allow_none=True, default_value=None)
layers = T.List(T.Instance(UnitSpec), allow_none=True, default_value=None, help="""Unit specs that will be layered.""")
name = T.Unicode(allow_none=True, default_value=None, help="""Name of the visualization for later reference.""")
transform = T.Instance(Transform, allow_none=True, default_value=None, help="""An object describing filter and new field calculation.""")
width = T.CFloat(allow_none=True, default_value=None)
def __init__(self, config=None, data=None, description=None, height=None, layers=None, name=None, transform=None, width=None, **kwargs):
kwds = dict(config=config, data=data, description=description, height=height, layers=layers, name=name, transform=transform, width=width)
kwargs.update({k:v for k, v in kwds.items() if v is not None})
super(LayerSpec, self).__init__(**kwargs)
selecting a particular matplotlib backend and loop integration.
"""
).tag(config=True)
pylab_import_all = Bool(True,
help="""If true, yap_ipython will populate the user namespace with numpy, pylab, etc.
and an ``import *`` is done from numpy and pylab, when using pylab mode.
When False, pylab mode should not import any names into the user namespace.
"""
).tag(config=True)
shell = Instance('yap_ipython.core.interactiveshell.InteractiveShellABC',
allow_none=True)
# whether interact-loop should start
interact = Bool(True)
user_ns = Instance(dict, args=None, allow_none=True)
@observe('user_ns')
def _user_ns_changed(self, change):
if self.shell is not None:
self.shell.user_ns = change['new']
self.shell.init_user_ns()
def init_path(self):
"""Add current working directory, '', to sys.path"""
if sys.path[0] != '':
sys.path.insert(0, '')
def init_shell(self):
raise NotImplementedError("Override in subclasses")
def init_gui_pylab(self):
"""Enable GUI event loop integration, taking pylab into account."""
class Transform(BaseObject):
"""Wrapper for Vega-Lite Transform definition.
Attributes
----------
calculate: List(Formula)
Calculate new field(s) using the provided expresssion(s).
filter: Union(Unicode, EqualFilter, RangeFilter, OneOfFilter, List(Union(Unicode, EqualFilter, RangeFilter, OneOfFilter)))
A string containing the filter Vega expression.
filterInvalid: Bool
Whether to filter invalid values (`null` and `NaN`) from the data.
"""
calculate = T.List(T.Instance(Formula, help="""Formula object for calculate."""), allow_none=True, default_value=None, help="""Calculate new field(s) using the provided expresssion(s).""")
filter = T.Union([T.Unicode(allow_none=True, default_value=None), T.Instance(EqualFilter, allow_none=True, default_value=None), T.Instance(RangeFilter, allow_none=True, default_value=None), T.Instance(OneOfFilter, allow_none=True, default_value=None), T.List(T.Union([T.Unicode(allow_none=True, default_value=None), T.Instance(EqualFilter, allow_none=True, default_value=None), T.Instance(RangeFilter, allow_none=True, default_value=None), T.Instance(OneOfFilter, allow_none=True, default_value=None)]), allow_none=True, default_value=None)])
filterInvalid = T.Bool(allow_none=True, default_value=None, help="""Whether to filter invalid values (`null` and `NaN`) from the data.""")
def __init__(self, calculate=None, filter=None, filterInvalid=None, **kwargs):
kwds = dict(calculate=calculate, filter=filter, filterInvalid=filterInvalid)
kwargs.update({k:v for k, v in kwds.items() if v is not None})
super(Transform, self).__init__(**kwargs)
def __init__(self, data, name=None, **kwargs):
super(DataArray, self).__init__(data=data, name=name, **kwargs)
class DataContainer(VtkWidget):
"""A structure that holds a sequence of DataArrays.
Represents things like Cells, Points, Verts, Lines, Strips, Polys,
CellData, and PointData.
"""
_model_name = Unicode('DataContainerModel').tag(sync=True)
kind = Unicode().tag(sync=True)
attributes = Dict().tag(sync=True)
data_arrays = VarTuple(Instance(DataArray)).tag(sync=True, **widget_serialization)
def __init__(self, kind, data_arrays=(), attributes=Undefined, **kwargs):
if attributes is Undefined:
attributes = {}
super(DataContainer, self).__init__(
kind=kind, data_arrays=data_arrays, attributes=attributes,
**kwargs
)
class DataSet(VtkWidget):
containers = VarTuple(Instance(DataContainer)).tag(sync=True, **widget_serialization)
def __init__(self, containers=(), **kwargs):
super(DataSet, self).__init__(
containers=containers,
**kwargs
# configurables
topics = List([''], config=True,
help="The ZMQ topics to subscribe to. Default is to subscribe to all messages")
url = Unicode(config=True,
help="ZMQ url on which to listen for log messages")
def _url_default(self):
return 'tcp://%s:20202' % localhost()
# internals
stream = Instance('zmq.eventloop.zmqstream.ZMQStream', allow_none=True)
context = Instance(zmq.Context)
def _context_default(self):
return zmq.Context.instance()
loop = Instance('tornado.ioloop.IOLoop')
def _loop_default(self):
return ioloop.IOLoop.current()
def __init__(self, **kwargs):
super(LogWatcher, self).__init__(**kwargs)
s = self.context.socket(zmq.SUB)
s.bind(self.url)
self.stream = zmqstream.ZMQStream(s, self.loop)
self.subscribe()
self.on_trait_change(self.subscribe, 'topics')
def start(self):
self.stream.on_recv(self.log_message)
def stop(self):
self.stream.stop_on_recv()
else:
value = local_value if local_value is not None else value
return value
def register_callback(self, callback, remove=False):
# (Un)Register the callback.
if remove and callback in self.callbacks:
self.callbacks.remove(callback)
elif not remove and callback not in self.callbacks:
self.callbacks.append(callback)
class Component(LoggingConfigurable):
comm = Instance('ipykernel.comm.Comm', allow_none=True)
_module = None
_msg_callbacks = Instance(CallbackDispatcher, ())
@property
def module(self):
if self._module is not None:
return self._module
else:
return self.__class__.__name__
def __init__(self, target_name='jupyter.react', props={}, comm=None):
self.target_name = target_name
self.props = props
if comm is None:
self.open(props)
else:
self.comm = comm
self.comm.on_close(self.close)