Skip to content

Add ArrayOrNone trait. #218

@mdickinson

Description

@mdickinson

In projects, we commonly need a trait that stores an optional array. Up until now, a good way of spelling that has been Either(None, Array(dtype=..., shape=...)).

However, with NumPy 1.9, the construction above gives the following warning:

>>> import numpy as np
>>> from traits.api import *
>>> class A(HasTraits):
...     foo = Either(None, Array)
... 
>>> a = A()
>>> a.foo = np.arange(3)
__main__:1: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.

We've worked around this in Mayavi and other projects by adding a custom ArrayOrNone trait type: see enthought/mayavi#146. It would be useful to have that ArrayOrNone trait directly available in Traits.

  • Implementation (re-use code from Mayavi)
  • Tests
  • Documentation
  • Make sure ArrayOrNone is exported in traits.api.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions