Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Traitlets types for NumPy, SciPy and friends

License

NotificationsYou must be signed in to change notification settings

jupyter-widgets/traittypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusDocumentation Status

Trait types for NumPy, SciPy and friends

Goals

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

which are out of the scope of the maintraitletsproject but are a common requirement to build applications with traitlets incombination with the scipy stack.

Another goal is to create adequate serialization and deserialization routinesfor these trait types to be used with theipywidgetsproject (to_json andfrom_json). These could also return a list of binarybuffers as allowed by the current messaging protocol.

Installation

Usingpip:

Make sure you havepip installed and run:

pip install traittypes

Usingconda:

conda install -c conda-forge traittypes

Usage

traittypes extends thetraitlets library with an implementation of trait types for numpy arrays, pandas dataframes, pandas series, xarray datasets and xarray dataarrays.

  • 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 constrain proposed values for the attribute.

For a general introduction totraitlets, check out thetraitlets documentation.

Example usage with a custom validator

fromtraitletsimportHasTraits,TraitErrorfromtraittypesimportArraydefshape(*dimensions):defvalidator(trait,value):ifvalue.shape!=dimensions:raiseTraitError('Expected an of shape %s and got and array with shape %s'% (dimensions,value.shape))else:returnvaluereturnvalidatorclassFoo(HasTraits):bar=Array(np.identity(2)).valid(shape(2,2))foo=Foo()foo.bar= [1,2]# Should raise a TraitError

About

Traitlets types for NumPy, SciPy and friends

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors12

Languages


[8]ページ先頭

©2009-2025 Movatter.jp