Skip to content

Commit

Permalink
Merge pull request #180 from scipp/relax-warning-policy
Browse files Browse the repository at this point in the history
Do not warn about fallback for empty groups
  • Loading branch information
SimonHeybrock authored Nov 9, 2023
2 parents 51666a7 + 0bd8ccb commit 75d36ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/scippnexus/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ def isclass(x):
return self._get_children_by_nx_class(sel)

dg = self._nexus.read_children(sel)
if not dg:
# Bail out early to avoid fallback warnings. Everything is optional in
# NeXus so we cannot assume that the group is invalid (in contrast to
# likely partially incomplete groups that will fail to assemble below).
return dg
try:
dg = self._nexus.assemble(dg)
except (sc.DimensionError, NexusStructureError) as e:
Expand Down
10 changes: 10 additions & 0 deletions tests/nexus_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)

import warnings

import h5py
import numpy as np
import pytest
Expand Down Expand Up @@ -552,3 +554,11 @@ def test_create_field_saves_errors(nxroot):
# Use allclose instead of identical because the variances are stored as stddevs
# which loses precision.
assert sc.allclose(loaded, data.rename_dims(d0='dim_0'))


@pytest.mark.parametrize('nxclass', [NXlog, NXmonitor, NXdetector, NXevent_data])
def test_empty_class_does_not_warn(nxroot, nxclass):
log = nxroot['entry'].create_class('log', nxclass)
with warnings.catch_warnings():
warnings.simplefilter("error")
log[()]

0 comments on commit 75d36ae

Please sign in to comment.