Skip to content

Cannot use reduction operations with spatial dtypes when masks are present #3271

@SimonHeybrock

Description

@SimonHeybrock
import scipp as sc

data = sc.vectors(dims=['x'], values=[[1,2,3],[2,3,4]])
mask = sc.array(dims=['x'], values=[False, True])
da = sc.DataArray(data, masks={'mask':mask})
da.sum()

Gives

---------------------------------------------------------------------------
DTypeError                                Traceback (most recent call last)
Cell In[2], line 6
      4 mask = sc.array(dims=['x'], values=[False, True])
      5 da = sc.DataArray(data, masks={'mask':mask})
----> 6 da.sum()

File ~/code/scipp/scipp/src/scipp/core/reduction.py:114, in sum(x, dim)
     87 """Sum of elements in the input.
     88 
     89 If the input data is in single precision (dtype='float32') this internally uses
   (...)
    111     Ignore NaN's when calculating the sum.
    112 """
    113 if dim is None:
--> 114     return _call_cpp_func(_cpp.sum, x)
    115 elif isinstance(dim, str):
    116     return _call_cpp_func(_cpp.sum, x, dim=dim)

File ~/code/scipp/scipp/src/scipp/core/_cpp_wrapper_util.py:15, in call_func(func, out, *args, **kwargs)
     13     return data_group_nary(func, *args, **kwargs)
     14 if out is None:
---> 15     return func(*args, **kwargs)
     16 else:
     17     return func(*args, **kwargs, out=out)

DTypeError: 'where' does not support dtypes 'bool', 'vector3', 'vector3', 

As indicated by the error message, this is because our where does not have these dtypes enables. The fix should be simple.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions