There is a difference between one-dimensional arrays and two-dimensional arrays in which one of the dimensions has size 1. You are trying to set a 1-D array into a CArray
trait expecting two dimensions. For example, your default method should be:
def _coordinate_default(self):
return np.array([[1., 2., 3.]])
(note the extra square brackets). The array you were setting is of shape (3,)
, not the desired (1, 3)
.
Similarly, it will not coerce a flat list into a 2-D array. Try assigning a nested list like
c.coordinate=[[1, 2, 3]]
instead.
(Alternatively, if you actually want 1-D arrays, you should use shape=(3,)
in your traits assignment and the other parts should work correctly.)