Skip to content
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
18 changes: 18 additions & 0 deletions src/chexus/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,24 @@ def validate(self, node: Dataset | Group) -> Violation | None:
return Violation(node.name, "NXlog must have a value")


class event_index_is_eight_bytes(Validator):
def __init__(self) -> None:
super().__init__(
"event_index_too_small", "event_index needs to be an 8 byte type"
)

def applies_to(self, node: Dataset | Group) -> bool:
return (
isinstance(node, Dataset)
and node.parent.attrs.get("NX_class") == "NXevent_data"
and node.name == 'event_index'
)

def validate(self, node: Dataset | Group) -> Violation | None:
if np.dtype(node.dtype).itemsize < 8:
return Violation(node.name, "event_index type too small")


def base_validators(*, has_scipp=True):
validators = [
depends_on_missing(),
Expand Down
24 changes: 24 additions & 0 deletions tests/validators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,27 @@ def test_NXdetector_pixel_offsets_are_unambiguous_2d_ids_allow_axis_attr() -> No
chexus.validators.NXdetector_pixel_offsets_are_unambiguous().validate(det)
is None
)


def test_event_index_is_eight_bytes() -> None:
parent = chexus.Group(name="event_data", attrs={"NX_class": "NXevent_data"})
good = chexus.Dataset(
name='event_index',
value=[1, 2, 3],
shape=(3,),
dtype='int64',
parent=parent,
)
bad = chexus.Dataset(
name='event_index',
value=[1, 2, 3],
shape=(3,),
dtype='int32',
parent=parent,
)
assert chexus.validators.event_index_is_eight_bytes().applies_to(good)
assert chexus.validators.event_index_is_eight_bytes().applies_to(bad)
assert chexus.validators.event_index_is_eight_bytes().validate(good) is None
assert isinstance(
chexus.validators.event_index_is_eight_bytes().validate(bad), chexus.Violation
)
Loading