How to use the traitlets.Union function in traitlets

To help you get started, we’ve selected a few traitlets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github altair-viz / altair / altair / schema / _interface / orderchanneldef.py View on Github external
Flag for binning a `quantitative` field, or a bin property object for binning parameters.
    field: Unicode
        Name of the field from which to pull a data value.
    sort: SortOrder
        
    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.""")
    sort = 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, sort=None, timeUnit=None, title=None, type=None, value=None, **kwargs):
        kwds = dict(aggregate=aggregate, bin=bin, field=field, 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(OrderChannelDef, self).__init__(**kwargs)
github creare-com / podpac / podpac / core / data / interpolation.py View on Github external
def interpolation_trait(default_value=INTERPOLATION_DEFAULT, allow_none=True, **kwargs):
    """Create a new interpolation trait
    
    Returns
    -------
    tl.Union
        Union trait for an interpolation definition
    """
    return tl.Union(
        [tl.Dict(), tl.List(), tl.Enum(INTERPOLATION_METHODS), tl.Instance(Interpolation)],
        allow_none=allow_none,
        default_value=default_value,
        **kwargs,
    )
github altair-viz / altair / altair / schema / _interface / positionchanneldef.py View on Github external
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 .""")
    axis = T.Union([T.Bool(allow_none=True, default_value=None), T.Instance(Axis, allow_none=True, default_value=None)])
    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.""")
    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, axis=None, bin=None, field=None, scale=None, sort=None, timeUnit=None, title=None, type=None, value=None, **kwargs):
        kwds = dict(aggregate=aggregate, axis=axis, bin=bin, field=field, 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(PositionChannelDef, self).__init__(**kwargs)
github creare-com / podpac / podpac / core / coordinates / uniform_coordinates1d.py View on Github external
When ctype != 'point', defines custom area bounds for the coordinates.
        *Note: To be replaced with segment_lengths.*

    See Also
    --------
    :class:`Coordinates1d`, :class:`ArrayCoordinates1d`, :class:`crange`, :class:`clinspace`
    """

    #:float, datetime64: Start coordinate.
    start = tl.Union([tl.Float(), tl.Instance(np.datetime64)])
    
    #:float, datetime64: Stop coordinate.
    stop = tl.Union([tl.Float(), tl.Instance(np.datetime64)])

    #:float, timedelta64: Signed, non-zero step between coordinates.
    step = tl.Union([tl.Float(), tl.Instance(np.timedelta64)])

    #:str: Dimension name, one of 'lat', 'lon', 'time', or 'alt'.
    name = tl.Enum(['lat', 'lon', 'time', 'alt'], allow_none=True)

    #: Units : Coordinate units.
    units = tl.Instance(Units, allow_none=True)

    #: str : Coordinate reference system.
    coord_ref_sys = tl.Enum(['WGS84', 'SPHER_MERC'], allow_none=True)

    #: str : Coordinates type, one of 'point', 'left', 'right', or 'midpoint'.
    ctype = tl.Enum(['point', 'left', 'right', 'midpoint'])

    #: : *To be replaced.*
    extents = tl.Instance(np.ndarray, allow_none=True, default_value=None)
github pbugnion / gmaps / gmaps / geotraitlets.py View on Github external
class Tilt(traitlets.Integer):
    """
    Integer representing a tilt degree allowed by Google Maps
    """
    info_text = 'tilt angle in degrees (either 0 or 45)'
    default_value = 45

    def validate(self, obj, value):
        if value in {0, 45}:
            return value
        else:
            self.error(obj, value)


class ColorAlpha(traitlets.Union):
    """
    Trait representing a color that can be passed to Google maps.

    This is either a string like 'blue' or '#aabbcc' or an RGB
    tuple like (100, 0, 250) or an RGBA tuple like (100, 0, 250, 0.5).
    """
    def __init__(
            self, default_value=traitlets.Undefined,
            allow_none=False, **metadata):
        trait_types = [
            ColorString(default_value=default_value, allow_none=allow_none),
            RgbTuple(),
            RgbaTuple()
        ]
        super(ColorAlpha, self).__init__(trait_types, **metadata)
github altair-viz / altair / altair / schema / _wrappers / channelwithlegend.py View on Github external
legend: LegendProperties
        
    scale: Scale
        
    sort: Union(SortField, SortOrder)
        
    timeUnit: TimeUnit
        
    type: Union(Type, Unicode)
        
    value: Union(CFloat, Unicode, Bool)
        
    """
    # Traitlets
    shorthand = T.Unicode('')
    type = T.Union([schema.Type(), T.Unicode()],
                   allow_none=True, default_value=None)

    @T.observe('shorthand')
    def _shorthand_changed(self, change):
        D = parse_shorthand(change['new'])
        for key, val in D.items():
            setattr(self, key, val)

    @T.observe('type')
    def _type_changed(self, change):
        new = change['new']
        if new in TYPE_ABBR:
            self.type = INV_TYPECODE_MAP[new]

    # Class Attributes
    skip = ['shorthand']
github hansohn / jupyterhub-ldap-authenticator / ldapauthenticator / ldapauthenticator.py View on Github external
will be discarded.
        """
    )

    server_pool_active = Union(
        [Bool(), Int()],
        default_value=True,
        config=True,
        help="""
        If True the ServerPool strategy will check for server availability. Set
        to Integer for maximum number of cycles to try before giving up
        (defaults to True).
        """
    )

    server_pool_exhaust = Union(
        [Bool(), Int()],
        default_value=False,
        config=True,
        help="""
        If True, any inactive servers will be removed from the pool. If set to
        an Integer, this will be the number of seconds an unreachable server is
        considered offline. When this timeout expires the server is reinserted
        in the pool and checked again for availability (defaults to False).
        """
    )

    bind_user_dn = Unicode(
        allow_none=True,
        default_value=None,
        config=True,
        help="""
github jupyterhub / kubespawner / kubespawner / spawner.py View on Github external
""",
        config=True,
        help="""
        Jinja2 template for constructing profile list shown to user.

        Used when `profile_list` is set.

        The contents of `profile_list` are passed in to the template.
        This should be used to construct the contents of a HTML form. When
        posted, this form is expected to have an item with name `profile` and
        the value the index of the profile in `profile_list`.
        """
    )

    profile_list = Union(
        trait_types=[
            List(trait=Dict()),
            Callable()
        ],
        config=True,
        help="""
        List of profiles to offer for selection by the user.

        Signature is: `List(Dict())`, where each item is a dictionary that has two keys:

        - `display_name`: the human readable display name (should be HTML safe)
        - `description`: Optional description of this profile displayed to the user.
        - `kubespawner_override`: a dictionary with overrides to apply to the KubeSpawner
          settings. Each value can be either the final value to change or a callable that
          take the `KubeSpawner` instance as parameter and return the final value.
        - `default`: (optional Bool) True if this is the default selected option
github hansohn / jupyterhub-ldap-authenticator / ldapauthenticator / ldapauthenticator.py View on Github external
import subprocess
import sys
from jupyterhub.auth import Authenticator
from jupyterhub.traitlets import Command
import ldap3
import ldap3.core.exceptions
from tornado import gen
from traitlets import Any, Int, Bool, List, Unicode, Union, default, observe


class LDAPAuthenticator(Authenticator):
    """
    LDAP Authenticator for Jupyterhub
    """

    server_hosts = Union(
        [List(), Unicode()],
        config=True,
        help="""
        List of Names, IPs, or the complete URLs in the scheme://host:port
        format of the server (required).
        """
    )

    server_port = Int(
        allow_none=True,
        default_value=None,
        config=True,
        help="""
        The port where the LDAP server is listening. Typically 389, for a
        cleartext connection, and 636 for a secured connection (defaults to None).
        """
github altair-viz / altair / altair / schema / _interface / unitencoding.py View on Github external
Text of the `text` mark.
    x: PositionChannelDef
        X coordinates for `point`, `circle`, `square`, `line`, `rule`, `text`, and `tick` (or to width and height for `bar` and `area` marks).
    x2: FieldDef
        X2 coordinates for ranged `bar`, `rule`, `area`.
    y: PositionChannelDef
        Y coordinates for `point`, `circle`, `square`, `line`, `rule`, `text`, and `tick` (or to width and height for `bar` and `area` marks).
    y2: FieldDef
        Y2 coordinates for ranged `bar`, `rule`, `area`.
    """
    color = T.Instance(ChannelDefWithLegend, allow_none=True, default_value=None, help="""Color of the marks - either fill or stroke color based on mark type.""")
    detail = T.Union([T.Instance(FieldDef, allow_none=True, default_value=None, help="""Interface for any kind of FieldDef."""), T.List(T.Instance(FieldDef, help="""Interface for any kind of FieldDef."""), allow_none=True, default_value=None)])
    label = T.Instance(FieldDef, allow_none=True, default_value=None)
    opacity = T.Instance(ChannelDefWithLegend, allow_none=True, default_value=None, help="""Opacity of the marks - either can be a value or in a range.""")
    order = T.Union([T.Instance(OrderChannelDef, allow_none=True, default_value=None), T.List(T.Instance(OrderChannelDef), allow_none=True, default_value=None)])
    path = T.Union([T.Instance(OrderChannelDef, allow_none=True, default_value=None), T.List(T.Instance(OrderChannelDef), allow_none=True, default_value=None)])
    shape = T.Instance(ChannelDefWithLegend, allow_none=True, default_value=None, help="""The symbol's shape (only for `point` marks).""")
    size = T.Instance(ChannelDefWithLegend, allow_none=True, default_value=None, help="""Size of the mark.""")
    text = T.Instance(FieldDef, allow_none=True, default_value=None, help="""Text of the `text` mark.""")
    x = T.Instance(PositionChannelDef, allow_none=True, default_value=None, help="""X coordinates for `point`, `circle`, `square`, `line`, `rule`, `text`, and `tick` (or to width and height for `bar` and `area` marks).""")
    x2 = T.Instance(FieldDef, allow_none=True, default_value=None, help="""X2 coordinates for ranged `bar`, `rule`, `area`.""")
    y = T.Instance(PositionChannelDef, allow_none=True, default_value=None, help="""Y coordinates for `point`, `circle`, `square`, `line`, `rule`, `text`, and `tick` (or to width and height for `bar` and `area` marks).""")
    y2 = T.Instance(FieldDef, allow_none=True, default_value=None, help="""Y2 coordinates for ranged `bar`, `rule`, `area`.""")
    
    def __init__(self, color=None, detail=None, label=None, opacity=None, order=None, path=None, shape=None, size=None, text=None, x=None, x2=None, y=None, y2=None, **kwargs):
        kwds = dict(color=color, detail=detail, label=label, opacity=opacity, order=order, path=path, shape=shape, size=size, text=text, x=x, x2=x2, y=y, y2=y2)
        kwargs.update({k:v for k, v in kwds.items() if v is not None})
        super(UnitEncoding, self).__init__(**kwargs)