scipp / chexus

Validate NeXus files
https://scipp.github.io/chexus/
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

Non-`str` valued `units` attributes raise an error #6

Closed g5t closed 10 months ago

g5t commented 10 months ago

If a group has a units attribute which is not a scalar string, the following will produce an error due to the use of the str startswith method: https://github.com/scipp/chexus/blob/245fd376d5e2f741a6fb2585e32e21a1b1a47fa1/src/chexus/validators.py#L99-L100

If non-scalar units attributes are invalid, then a Violation should be returned, e.g.,

if not isinstance(units, str):
    return Violation(node.name, f'Invalid units type {type(units)}')
if units.startswith('NX_') or units in invalid:
    return Violation(node.name, f'Invalid units {units}')

Non-scalar units do not appear to be supported by scippnexus, but are inserted by the File Writer for hs00 histogram streams. It's not clear if this is required/expected/desired behavior (see, e.g., https://jira.esss.lu.se/browse/ECDC-3712)