jupyter-widgets/traittypes

Name: traittypes

Owner: Jupyter Widgets

Description: Traitlets types for NumPy, SciPy and friends

Created: 2015-10-29 13:30:38.0

Updated: 2018-05-09 12:01:46.0

Pushed: 2018-05-09 12:01:44.0

Homepage: null

Size: 38

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Scipy Trait Types

Build Status Documentation Status

Trait types for NumPy, SciPy and friends

Goals

Provide a reference implementation of trait types for common data structures used in the scipy stack such as

which are out of the scope of the main traitlets project but are a common requirement to build applications with traitlets in combination with the scipy stack.

Another goal is to create adequate serialization and deserialization routines for these trait types to be used with the ipywidgets project (to_json and from_json). These could also return a list of binary buffers as allowed by the current messaging protocol.

Installation

Using pip:

Make sure you have pip installed and run:

install traittypes

Using conda:

a install -c conda-forge traittypes
Usage

traittypes extends the traitlets library with an implementation of trait types for numpy arrays, pandas dataframes and pandas series.

For a general introduction to traitlets, check out the traitlets documentation.

Example usage with a custom validator
 traitlets import HasTraits, TraitError
 traittypes import Array

shape(*dimensions):
def validator(trait, value):
    if value.shape != dimensions:
        raise TraitError('Expected an of shape %s and got and array with shape %s' % (dimensions, value.shape))
    else:
        return value
return validator

s Foo(HasTraits):
bar = Array(np.identity(2)).valid(shape(2, 2))
= Foo()

bar = [1, 2]  # Should raise a TraitError

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.