Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not warn about fallback for empty groups #180

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[()]