How to use the traittypes.traittypes.PandasType function in traittypes

To help you get started, we’ve selected a few traittypes 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 jupyter-widgets / traittypes / traittypes / traittypes.py View on Github external
def validate(self, obj, value):
        if value is None and not self.allow_none:
            self.error(obj, value)
        if value is None or value is Undefined:
            return super(PandasType, self).validate(obj, value)
        try:
            value = self.klass(value)
        except (ValueError, TypeError) as e:
            raise TraitError(e)
        return super(PandasType, self).validate(obj, value)
github jupyter-widgets / traittypes / traittypes / traittypes.py View on Github external
class DataFrame(PandasType):

    """A pandas dataframe trait type."""

    info_text = 'a pandas dataframe'

    def __init__(self, default_value=Empty, allow_none=False, dtype=None, **kwargs):
        if 'klass' not in kwargs and self.klass is None:
            import pandas as pd
            kwargs['klass'] = pd.DataFrame
        super(DataFrame, self).__init__(
            default_value=default_value, allow_none=allow_none, dtype=dtype, **kwargs)


class Series(PandasType):

    """A pandas series trait type."""

    info_text = 'a pandas series'
    dtype = None

    def __init__(self, default_value=Empty, allow_none=False, dtype=None, **kwargs):
        if 'klass' not in kwargs and self.klass is None:
            import pandas as pd
            kwargs['klass'] = pd.Series
        super(Series, self).__init__(
            default_value=default_value, allow_none=allow_none, dtype=dtype, **kwargs)
        self.dtype = dtype


class XarrayType(SciType):
github jupyter-widgets / traittypes / traittypes / traittypes.py View on Github external
raise TraitError('The klass attribute must be a class'
                                ' not: %r' % klass)
        if default_value is Empty:
            default_value = klass()
        elif default_value is not None and default_value is not Undefined:
            default_value = klass(default_value)
        super(PandasType, self).__init__(default_value=default_value, allow_none=allow_none, **kwargs)

    def make_dynamic_default(self):
        if self.default_value is None or self.default_value is Undefined:
            return self.default_value
        else:
            return self.default_value.copy()


class DataFrame(PandasType):

    """A pandas dataframe trait type."""

    info_text = 'a pandas dataframe'

    def __init__(self, default_value=Empty, allow_none=False, dtype=None, **kwargs):
        if 'klass' not in kwargs and self.klass is None:
            import pandas as pd
            kwargs['klass'] = pd.DataFrame
        super(DataFrame, self).__init__(
            default_value=default_value, allow_none=allow_none, dtype=dtype, **kwargs)


class Series(PandasType):

    """A pandas series trait type."""