From 0e64b44035ec4e753ae4ef1452616faff75504a5 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Tue, 15 Oct 2024 10:15:26 +0200 Subject: [PATCH] fix: nxlog use time field as signal if missing --- src/scippnexus/nxdata.py | 2 +- tests/nxlog_test.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/scippnexus/nxdata.py b/src/scippnexus/nxdata.py index cc8fbc3d..3aac9948 100644 --- a/src/scippnexus/nxdata.py +++ b/src/scippnexus/nxdata.py @@ -486,7 +486,7 @@ def __init__(self, attrs: dict[str, Any], children: dict[str, Field | Group]): attrs=attrs, children=children, fallback_dims=('time',), - fallback_signal_name='value', + fallback_signal_name='value' if 'value' in children else 'time', ) def read_children(self, sel: ScippIndex) -> sc.DataGroup: diff --git a/tests/nxlog_test.py b/tests/nxlog_test.py index 44b9e2d1..0cbf5e4f 100644 --- a/tests/nxlog_test.py +++ b/tests/nxlog_test.py @@ -52,16 +52,14 @@ def test_nxobject_log(h5root): assert sc.identical(log[...], da) -@pytest.mark.filterwarnings("ignore:Failed to load /entry/log:UserWarning") -def test_nxlog_with_missing_value_triggers_fallback(nxroot): +def test_nxlog_with_missing_value_uses_time_as_value(nxroot): time = sc.epoch(unit='ns') + sc.array( dims=['time'], unit='s', values=[4.4, 5.5, 6.6] ).to(unit='ns', dtype='int64') log = nxroot['entry'].create_class('log', NXlog) log['time'] = time - sc.epoch(unit='ns') loaded = log[()] - # Fallback to DataGroup, but we still have partial info from NXlog: dim is time - assert_identical(loaded, sc.DataGroup(time=time)) + assert_identical(loaded, sc.DataArray(data=time)) def test_nxlog_length_1(h5root):