From 6590a37a747dd1d985e69c62e5cc83f4557183b5 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Wed, 1 Jun 2022 15:37:53 +0200 Subject: [PATCH 1/4] Update to scipp-0.14 --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From d61dca9b250f4dfb6b2f1abbc4c4b49b091edf69 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Wed, 1 Jun 2022 15:46:53 +0200 Subject: [PATCH 2/4] Fix and test IndexError --- src/scippnexus/nxevent_data.py | 3 +-- tests/nexus_test.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/scippnexus/nxevent_data.py b/src/scippnexus/nxevent_data.py index 6fe725f5..8041025d 100644 --- a/src/scippnexus/nxevent_data.py +++ b/src/scippnexus/nxevent_data.py @@ -13,7 +13,6 @@ class NXevent_data(NXobject): - @property def shape(self) -> List[int]: return self['event_index'].shape @@ -120,7 +119,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', From e6a8925aa122a45dc7ee8f9038bba20e1fd6d9f0 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Wed, 1 Jun 2022 15:47:14 +0200 Subject: [PATCH 3/4] Scipp now uses tuple instead of list --- tests/nxdetector_test.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/nxdetector_test.py b/tests/nxdetector_test.py index c9daf1c6..43f9be85 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): @@ -225,7 +225,6 @@ def test_nxevent_data_selection_yields_correct_pulses(nxroot): create_event_data_ids_1234(detector.create_class('events', NX_class.NXevent_data)) class Load: - def __getitem__(self, select=...): da = detector['events'][select] return da.bins.size().values From 606a58a474be9b2b229d0b088769ce3965067301 Mon Sep 17 00:00:00 2001 From: SimonHeybrock Date: Wed, 1 Jun 2022 13:48:49 +0000 Subject: [PATCH 4/4] Apply automatic formatting --- src/scippnexus/nxevent_data.py | 1 + tests/nxdetector_test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/scippnexus/nxevent_data.py b/src/scippnexus/nxevent_data.py index 8041025d..6cbb0f04 100644 --- a/src/scippnexus/nxevent_data.py +++ b/src/scippnexus/nxevent_data.py @@ -13,6 +13,7 @@ class NXevent_data(NXobject): + @property def shape(self) -> List[int]: return self['event_index'].shape diff --git a/tests/nxdetector_test.py b/tests/nxdetector_test.py index 43f9be85..a4200963 100644 --- a/tests/nxdetector_test.py +++ b/tests/nxdetector_test.py @@ -225,6 +225,7 @@ def test_nxevent_data_selection_yields_correct_pulses(nxroot): create_event_data_ids_1234(detector.create_class('events', NX_class.NXevent_data)) class Load: + def __getitem__(self, select=...): da = detector['events'][select] return da.bins.size().values