None
Test: nexusfiles-scipp|tbl|load_raw_file|
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
None
instrument = 'tbl'
coda_nexus_file_path = PosixPath('/ess/data/coda/2025/999999/raw/999999_00084821.hdf')
def test_load_raw_file(instrument: str, coda_nexus_file_path: Path) -> None:
# Catch the warnings while loading the file to avoid the test from stopping after
# the first warning.
# Note that we need action="default" to make sure that the warnings are not
# promoted as errors.
with warnings.catch_warnings(action="default", record=True) as recorded_warnings:
with sx.File(coda_nexus_file_path, "r", locking=False) as f:
> dg = f[()]
^^^^^
tests/nexusfiles-scipp/fileloading_test.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:345: in read_children
return super().read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:341: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:598: in __getitem__
da = _group_events(event_data=events, grouping=self._grouping[detector_sel])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:776: in _group_events
event_data = event_data.bins.constituents['data'].group(event_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/data_group.py:744: in impl
return func(data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/binning.py:1165: in group
return make_binned(x, groups=groups, erase=erase)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x =
Dimensions: Sizes[event:0, ]
Coordinates:
* event_id int32
Data:
float32 [counts] (event) []
def make_binned(
x: Variable | DataArray,
*,
edges: Sequence[Variable] | None = None,
groups: Sequence[Variable] | None = None,
erase: Sequence[str] = (),
) -> DataArray:
"""Create binned data by binning input along all dimensions given by edges or
groups.
Usually :py:func:`scipp.bin` or :py:func:`scipp.group` should be preferred,
unless the more precise control over which dimensions should be erased is required,
or unless grouping and binning at the same time is required.
This does not histogram the data, each output bin will contain a "list" of
input values.
At least one argument of ``edges`` and ``groups`` is required.
If the input is binned and certain bins are masked then changing the binning
will apply the masks, i.e., masked bins are treated as empty.
Warning
-------
When there is existing binning or grouping, the algorithm assumes that coordinates
of the binned data are correct, i.e., compatible with the corresponding
coordinate values in the individual bins. If this is not the case then the behavior
is UNSPECIFIED. That is, the algorithm may or may not ignore the existing
coordinates. If you encounter such as case, remove the conflicting coordinate,
e.g., using :py:func:`scipp.DataArray.drop_coords`.
Parameters
----------
x:
Input data.
edges:
Bin edges, one per dimension to bin in.
groups:
Keys to group input by one per dimension to group in.
erase:
Dimension labels to remove from output.
Returns
-------
:
Binned ``x``.
See Also
--------
scipp.hist:
For histogramming data.
scipp.bin:
Recommended interface for binning data.
scipp.group:
Recommended interface for grouping data.
scipp.bins:
For creating binned data based on explicitly given index ranges.
"""
if groups is None:
groups = []
if edges is None:
edges = []
_check_erase_dimension_clash(erase, *edges, *groups)
if isinstance(x, Variable) and x.bins is not None:
x = DataArray(x)
elif isinstance(x, Variable):
coords = [*edges, *groups]
if len(coords) != 1:
raise ValueError(
"Edges for exactly one dimension must be specified when "
"binning or histogramming a variable."
)
data = scalar(1.0, unit='counts').broadcast(sizes=x.sizes).copy()
x = DataArray(data, coords={coords[0].dim: x})
if _can_operate_on_bins(x, edges, groups, erase):
return combine_bins(x, edges=edges, groups=groups, dim=erase)
# Many-to-many mapping is expensive, concat first is generally cheaper,
# despite extra copies. If some coords are dense, perform binning in two steps,
# since concat is not possible then (without mapping dense coords to binned coords,
# which might bypass some other optimizations).
if erase and x.bins is not None:
dense_edges = [var for var in edges if var.dims[-1] not in x.bins.coords]
dense_groups = [var for var in groups if var.dims[-1] not in x.bins.coords]
if len(dense_edges) + len(dense_groups) == 0:
x = x.bins.concat(erase)
erase = ()
elif len(dense_edges) + len(dense_groups) < len(edges) + len(groups):
x = make_binned(x, edges=dense_edges, groups=dense_groups, erase=erase)
b: Bins[DataArray] = x.bins # type: ignore[assignment]
edges = [var for var in edges if var.dims[-1] in b.coords]
groups = [var for var in groups if var.dims[-1] in b.coords]
erase = ()
if x.ndim == 0:
return ( # type: ignore[no-any-return]
_cpp.bin(x.value, edges, groups, erase)
.assign_coords(x.coords)
.assign_masks(x.masks)
)
x = _prepare_multi_dim_dense(x, *edges, *groups)
> return _cpp.bin(x, edges, groups, erase) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E scipp._scipp.core.DTypeError: 'scipp.bin.update_indices_by_grouping' does not support dtypes 'int32', 'int32', 'unordered_map_float32_to_int32',
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/binning.py:213: DTypeError
instrument = 'tbl'
coda_nexus_file_path = PosixPath('/ess/data/coda/2025/999999/raw/999999_00084692.hdf')
def test_load_raw_file(instrument: str, coda_nexus_file_path: Path) -> None:
# Catch the warnings while loading the file to avoid the test from stopping after
# the first warning.
# Note that we need action="default" to make sure that the warnings are not
# promoted as errors.
with warnings.catch_warnings(action="default", record=True) as recorded_warnings:
with sx.File(coda_nexus_file_path, "r", locking=False) as f:
> dg = f[()]
^^^^^
tests/nexusfiles-scipp/fileloading_test.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:345: in read_children
return super().read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:341: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:598: in __getitem__
da = _group_events(event_data=events, grouping=self._grouping[detector_sel])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:776: in _group_events
event_data = event_data.bins.constituents['data'].group(event_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/data_group.py:744: in impl
return func(data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/binning.py:1165: in group
return make_binned(x, groups=groups, erase=erase)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x =
Dimensions: Sizes[event:0, ]
Coordinates:
* event_id int32
Data:
float32 [counts] (event) []
def make_binned(
x: Variable | DataArray,
*,
edges: Sequence[Variable] | None = None,
groups: Sequence[Variable] | None = None,
erase: Sequence[str] = (),
) -> DataArray:
"""Create binned data by binning input along all dimensions given by edges or
groups.
Usually :py:func:`scipp.bin` or :py:func:`scipp.group` should be preferred,
unless the more precise control over which dimensions should be erased is required,
or unless grouping and binning at the same time is required.
This does not histogram the data, each output bin will contain a "list" of
input values.
At least one argument of ``edges`` and ``groups`` is required.
If the input is binned and certain bins are masked then changing the binning
will apply the masks, i.e., masked bins are treated as empty.
Warning
-------
When there is existing binning or grouping, the algorithm assumes that coordinates
of the binned data are correct, i.e., compatible with the corresponding
coordinate values in the individual bins. If this is not the case then the behavior
is UNSPECIFIED. That is, the algorithm may or may not ignore the existing
coordinates. If you encounter such as case, remove the conflicting coordinate,
e.g., using :py:func:`scipp.DataArray.drop_coords`.
Parameters
----------
x:
Input data.
edges:
Bin edges, one per dimension to bin in.
groups:
Keys to group input by one per dimension to group in.
erase:
Dimension labels to remove from output.
Returns
-------
:
Binned ``x``.
See Also
--------
scipp.hist:
For histogramming data.
scipp.bin:
Recommended interface for binning data.
scipp.group:
Recommended interface for grouping data.
scipp.bins:
For creating binned data based on explicitly given index ranges.
"""
if groups is None:
groups = []
if edges is None:
edges = []
_check_erase_dimension_clash(erase, *edges, *groups)
if isinstance(x, Variable) and x.bins is not None:
x = DataArray(x)
elif isinstance(x, Variable):
coords = [*edges, *groups]
if len(coords) != 1:
raise ValueError(
"Edges for exactly one dimension must be specified when "
"binning or histogramming a variable."
)
data = scalar(1.0, unit='counts').broadcast(sizes=x.sizes).copy()
x = DataArray(data, coords={coords[0].dim: x})
if _can_operate_on_bins(x, edges, groups, erase):
return combine_bins(x, edges=edges, groups=groups, dim=erase)
# Many-to-many mapping is expensive, concat first is generally cheaper,
# despite extra copies. If some coords are dense, perform binning in two steps,
# since concat is not possible then (without mapping dense coords to binned coords,
# which might bypass some other optimizations).
if erase and x.bins is not None:
dense_edges = [var for var in edges if var.dims[-1] not in x.bins.coords]
dense_groups = [var for var in groups if var.dims[-1] not in x.bins.coords]
if len(dense_edges) + len(dense_groups) == 0:
x = x.bins.concat(erase)
erase = ()
elif len(dense_edges) + len(dense_groups) < len(edges) + len(groups):
x = make_binned(x, edges=dense_edges, groups=dense_groups, erase=erase)
b: Bins[DataArray] = x.bins # type: ignore[assignment]
edges = [var for var in edges if var.dims[-1] in b.coords]
groups = [var for var in groups if var.dims[-1] in b.coords]
erase = ()
if x.ndim == 0:
return ( # type: ignore[no-any-return]
_cpp.bin(x.value, edges, groups, erase)
.assign_coords(x.coords)
.assign_masks(x.masks)
)
x = _prepare_multi_dim_dense(x, *edges, *groups)
> return _cpp.bin(x, edges, groups, erase) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E scipp._scipp.core.UnitError: Expected unit None, got m.
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/binning.py:213: UnitError
instrument = 'tbl'
coda_nexus_file_path = PosixPath('/ess/data/coda/2025/999999/raw/999999_00084552.hdf')
def test_load_raw_file(instrument: str, coda_nexus_file_path: Path) -> None:
# Catch the warnings while loading the file to avoid the test from stopping after
# the first warning.
# Note that we need action="default" to make sure that the warnings are not
# promoted as errors.
with warnings.catch_warnings(action="default", record=True) as recorded_warnings:
with sx.File(coda_nexus_file_path, "r", locking=False) as f:
> dg = f[()]
^^^^^
tests/nexusfiles-scipp/fileloading_test.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:78: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:378: in __getitem__
dg = self._nexus.read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:345: in read_children
return super().read_children(sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/base.py:93: in read_children
name: self.index_child(child, sel)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:341: in index_child
return child[child_sel]
^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:598: in __getitem__
da = _group_events(event_data=events, grouping=self._grouping[detector_sel])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scippnexus/nxdata.py:776: in _group_events
event_data = event_data.bins.constituents['data'].group(event_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/data_group.py:744: in impl
return func(data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/binning.py:1165: in group
return make_binned(x, groups=groups, erase=erase)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x =
Dimensions: Sizes[event:0, ]
Coordinates:
* event_id int32
Data:
float32 [counts] (event) []
def make_binned(
x: Variable | DataArray,
*,
edges: Sequence[Variable] | None = None,
groups: Sequence[Variable] | None = None,
erase: Sequence[str] = (),
) -> DataArray:
"""Create binned data by binning input along all dimensions given by edges or
groups.
Usually :py:func:`scipp.bin` or :py:func:`scipp.group` should be preferred,
unless the more precise control over which dimensions should be erased is required,
or unless grouping and binning at the same time is required.
This does not histogram the data, each output bin will contain a "list" of
input values.
At least one argument of ``edges`` and ``groups`` is required.
If the input is binned and certain bins are masked then changing the binning
will apply the masks, i.e., masked bins are treated as empty.
Warning
-------
When there is existing binning or grouping, the algorithm assumes that coordinates
of the binned data are correct, i.e., compatible with the corresponding
coordinate values in the individual bins. If this is not the case then the behavior
is UNSPECIFIED. That is, the algorithm may or may not ignore the existing
coordinates. If you encounter such as case, remove the conflicting coordinate,
e.g., using :py:func:`scipp.DataArray.drop_coords`.
Parameters
----------
x:
Input data.
edges:
Bin edges, one per dimension to bin in.
groups:
Keys to group input by one per dimension to group in.
erase:
Dimension labels to remove from output.
Returns
-------
:
Binned ``x``.
See Also
--------
scipp.hist:
For histogramming data.
scipp.bin:
Recommended interface for binning data.
scipp.group:
Recommended interface for grouping data.
scipp.bins:
For creating binned data based on explicitly given index ranges.
"""
if groups is None:
groups = []
if edges is None:
edges = []
_check_erase_dimension_clash(erase, *edges, *groups)
if isinstance(x, Variable) and x.bins is not None:
x = DataArray(x)
elif isinstance(x, Variable):
coords = [*edges, *groups]
if len(coords) != 1:
raise ValueError(
"Edges for exactly one dimension must be specified when "
"binning or histogramming a variable."
)
data = scalar(1.0, unit='counts').broadcast(sizes=x.sizes).copy()
x = DataArray(data, coords={coords[0].dim: x})
if _can_operate_on_bins(x, edges, groups, erase):
return combine_bins(x, edges=edges, groups=groups, dim=erase)
# Many-to-many mapping is expensive, concat first is generally cheaper,
# despite extra copies. If some coords are dense, perform binning in two steps,
# since concat is not possible then (without mapping dense coords to binned coords,
# which might bypass some other optimizations).
if erase and x.bins is not None:
dense_edges = [var for var in edges if var.dims[-1] not in x.bins.coords]
dense_groups = [var for var in groups if var.dims[-1] not in x.bins.coords]
if len(dense_edges) + len(dense_groups) == 0:
x = x.bins.concat(erase)
erase = ()
elif len(dense_edges) + len(dense_groups) < len(edges) + len(groups):
x = make_binned(x, edges=dense_edges, groups=dense_groups, erase=erase)
b: Bins[DataArray] = x.bins # type: ignore[assignment]
edges = [var for var in edges if var.dims[-1] in b.coords]
groups = [var for var in groups if var.dims[-1] in b.coords]
erase = ()
if x.ndim == 0:
return ( # type: ignore[no-any-return]
_cpp.bin(x.value, edges, groups, erase)
.assign_coords(x.coords)
.assign_masks(x.masks)
)
x = _prepare_multi_dim_dense(x, *edges, *groups)
> return _cpp.bin(x, edges, groups, erase) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E scipp._scipp.core.UnitError: Expected unit None, got m.
.tox/nexusfiles-scipp-tbl/lib/python3.12/site-packages/scipp/core/binning.py:213: UnitError
None
None
None