BIDS/datarray

Datarray-specific fields should be present when returning scalars from reductions

fperez opened this issue · 0 comments

When an operation reduces the number of dimensions to zero, numpy returns a numpy scalar object:

In [33]: a = rand(10,10,10)

In [34]: a.sum()
Out[34]: 484.51400807908772

In [35]: _34.ndim
Out[35]: 0

In [36]: _34.shape
Out[36]: ()

For datarray, we can return scalars, but they will be plain numpy scalars, they won't have the extra datarray-specific fields (like labels, axes, ...). We can't add new fields to numpy scalars:

In [40]: _34.newfield=1
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'numpy.float64' object has no attribute 'newfield'

So this is not likely to change soon, but we want to record it here for later reference. If datarray is included in numpy, it may be easier to play with the scalar code to make datarray scalars have all the necessary fields.