GithubHelp home page GithubHelp logo

alexxnica / traittypes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jupyter-widgets/traittypes

0.0 1.0 0.0 30 KB

Traitlets types for NumPy, SciPy and friends

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

traittypes's Introduction

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:

pip install traittypes

Using conda:

conda 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.

  • traittypes works around some limitations with numpy array comparison to only trigger change events when necessary.
  • traittypes also extends the traitlets API for adding custom validators to constained proposed values for the attribute.

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

Example usage with a custom validator

from traitlets import HasTraits, TraitError
from traittypes import Array

def 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

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

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

traittypes's People

Contributors

sylvaincorlay avatar ellisonbg avatar jasongrout avatar minrk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.