diff --git a/requirements/base.txt b/requirements/base.txt index 78d824d9..b54082f8 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -20,7 +20,7 @@ python-dateutil==2.8.2 # via -r requirements/base.in pyyaml==6.0 # via confuse -scipp==0.13.1 +scipp==0.14.0 # via -r requirements/base.in scipy==1.8.0 # via -r requirements/base.in diff --git a/src/scippnexus/nxevent_data.py b/src/scippnexus/nxevent_data.py index 6fe725f5..6cbb0f04 100644 --- a/src/scippnexus/nxevent_data.py +++ b/src/scippnexus/nxevent_data.py @@ -120,7 +120,7 @@ def _getitem(self, select: ScippIndex) -> sc.DataArray: try: binned = sc.bins(data=events, dim=_event_dimension, begin=begins, end=ends) - except sc.SliceError as e: + except IndexError as e: raise IndexError( f"Invalid index in NXevent_data at {self.name}/event_index:\n{e}.") diff --git a/tests/nexus_test.py b/tests/nexus_test.py index 41c937a8..c0636225 100644 --- a/tests/nexus_test.py +++ b/tests/nexus_test.py @@ -289,6 +289,16 @@ def test_negative_event_index_converted_to_num_event(nxroot): assert events.bins.size().values[3] == 0 +def test_bad_event_index_raises_IndexError(nxroot): + event_data = nxroot['entry'].create_class('events_0', NX_class.NXevent_data) + event_data['event_id'] = sc.array(dims=[''], unit=None, values=[1, 2, 4, 1, 2]) + event_data['event_time_offset'] = sc.array(dims=[''], unit='s', values=[0, 0, 0, 0]) + event_data['event_time_zero'] = sc.array(dims=[''], unit='s', values=[1, 2, 3, 4]) + event_data['event_index'] = sc.array(dims=[''], unit=None, values=[0, 3, 3, 666]) + with pytest.raises(IndexError): + nxroot['entry/events_0'][...] + + def create_event_data_without_event_id(group): group['event_time_offset'] = sc.array(dims=[''], unit='s', diff --git a/tests/nxdetector_test.py b/tests/nxdetector_test.py index c9daf1c6..a4200963 100644 --- a/tests/nxdetector_test.py +++ b/tests/nxdetector_test.py @@ -208,8 +208,8 @@ def test_loading_event_data_with_full_selection_and_automatic_detector_numbers_w detector = nxroot.create_class('detector0', NX_class.NXdetector) create_event_data_ids_1234(detector.create_class('events', NX_class.NXevent_data)) assert detector.dims == ['detector_number'] - assert detector[...].shape == [4] - assert detector[()].shape == [4] + assert tuple(detector[...].shape) == (4, ) + assert tuple(detector[()].shape) == (4, ) def test_event_data_field_dims_labels(nxroot):