Repository navigation
Allow writing annotation files with no events - #796
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks, this looks good. An empty annotation with no fs writes just the end marker (00 00). With fs or custom labels, it writes the usual header followed by the end marker, the same bytes the writer already produces for non-empty files. Both read back correctly with read_annotations and rdann, including with start/stop and summarize_labels=True. Empty float arrays, all-empty event fields and an empty merge_annotations result written with wrann also work. A non-empty annotation without a label field, and an empty sample with a non-empty symbol, are still rejected. The offline suite, Ruff and the strict docs build pass locally.
Not for this PR, but related: the new write path still passes on some old error styles. A non-empty annotation with no label field raises a bare Exception with a tuple message, and sample=[] (a list) raises TypeError: ('The sample field must be one of the following types:', (<class 'numpy.ndarray'>,)). It would be good for write_annotations and Annotation.write to raise ValueError or TypeError with plain messages, as the new readers now do. I'm happy to open an issue for that.
Ready to merge once CI is green.
Summary
An empty result from
merge_annotationscould not be saved because the annotation writer required at least one event. This PR allows zero-event annotation files in the shared writer used bywrite_annotations,Annotation.write, andAnnotation.wrann.Empty files can still carry sampling frequency and custom label definitions. Event fields are validated for consistent lengths before writing, and the result can be read back with
read_annotations.Verification