- Notifications
You must be signed in to change notification settings - Fork22
Traitlets types for NumPy, SciPy and friends
License
jupyter-widgets/traittypes
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Trait types for NumPy, SciPy and friends
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.
Usingpip:
Make sure you havepip installed and run:
pip install traittypesUsingconda:
conda install -c conda-forge traittypestraittypes extends thetraitlets library with an implementation of trait types for numpy arrays, pandas dataframes, pandas series, xarray datasets and xarray dataarrays.
traittypesworks around some limitations with numpy array comparison to only trigger change events when necessary.traittypesalso extends the traitlets API for adding custom validators to constrain proposed values for the attribute.
For a general introduction totraitlets, check out thetraitlets documentation.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.