Repository: scipp/scippnexus

Issue:
Loading empty `event_time_zero` slice seems to load everything
```python
import scippnexus.v2 as snx
# ...
dg = f['event_time_zero', 0:1]  # ok, loads one pulse
dg = f['event_time_zero', 0:0]  # seems to load everything?
```

Discussion:

Patch:
diff --git a/src/scippnexus/v2/nxevent_data.py b/src/scippnexus/v2/nxevent_data.py
index fdf0cbe..320e0ba 100644
--- a/src/scippnexus/v2/nxevent_data.py
+++ b/src/scippnexus/v2/nxevent_data.py
@@ -78,7 +78,7 @@ class NXevent_data(NXobject):
             event_select = slice(event_index[0],
                                  event_index[-1] if last_loaded else num_event)
         else:
-            event_select = slice(None)
+            event_select = slice(0, 0)
 
         event_time_offset = children['event_time_offset'][event_select]
 


Test patch:
diff --git a/tests/nxdetector_test.py b/tests/nxdetector_test.py
index 0b4bc92..271433b 100644
--- a/tests/nxdetector_test.py
+++ b/tests/nxdetector_test.py
@@ -326,14 +326,16 @@ def test_event_data_field_dims_labels(nxroot):
     assert detector['detector_number'].dims == ('detector_number', )
 
 
-def test_nxevent_data_selection_yields_correct_pulses(nxroot):
+def test_nxevent_data_without_detector_number_selection_yields_correct_pulses(nxroot):
     detector = nxroot.create_class('detector0', NXdetector)
     create_event_data_ids_1234(detector.create_class('events', snx.NXevent_data))
 
     class Load:
 
         def __getitem__(self, select=...):
-            da = detector['events'][select]
+            da = detector[select]
+            assert da.bins.size().sum(
+            ).value == da.bins.constituents['data'].sizes['event']
             return da.bins.size().values
 
     assert np.array_equal(Load()[...], [3, 0, 2, 1])
@@ -355,6 +357,38 @@ def test_nxevent_data_selection_yields_correct_pulses(nxroot):
     assert np.array_equal(Load()['event_time_zero', :-2], [3, 0])
 
 
+def test_nxevent_data_selection_yields_correct_pulses(nxroot):
+    detector_numbers = sc.array(dims=[''], unit=None, values=np.array([1, 2, 3, 4]))
+    detector = nxroot.create_class('detector0', NXdetector)
+    detector.create_field('detector_number', detector_numbers)
+    create_event_data_ids_1234(detector.create_class('events', snx.NXevent_data))
+
+    class Load:
+
+        def __getitem__(self, select=...):
+            da = detector[select]
+            return da.bins.size().values
+
+    assert np.array_equal(Load()[...], [2, 3, 0, 1])
+    assert np.array_equal(Load()['event_time_zero', 0], [1, 1, 0, 1])
+    assert np.array_equal(Load()['event_time_zero', 1], [0, 0, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 2], [1, 1, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 3], [0, 1, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', -1], [0, 1, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', -2], [1, 1, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 0:0], [0, 0, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 1:1], [0, 0, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 1:-3], [0, 0, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 3:3], [0, 0, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', -1:-1], [0, 0, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', 0:1], [1, 1, 0, 1])
+    assert np.array_equal(Load()['event_time_zero', 0:-3], [1, 1, 0, 1])
+    assert np.array_equal(Load()['event_time_zero', -1:], [0, 1, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', -2:-1], [1, 1, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', -2:], [1, 2, 0, 0])
+    assert np.array_equal(Load()['event_time_zero', :-2], [1, 1, 0, 1])
+
+
 def create_off_geometry_detector_numbers_1234(group: snx.Group,
                                               name: str,
                                               detector_faces: bool = True