Repository navigation
Add channels alias to Annotation - #810
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks. channels comes straight from the #672 table, shares one array with chan through copies and pickling, and validates assignments the same way as the writer (#799): lists, 2D arrays, strings, booleans (including in object arrays), fractions, NaN and values outside 0–255 are rejected, while chan keeps its existing behaviour. All 15 annotation files in sample-data and a merge_annotations result produce int64 channel arrays that assign back through the new name, so the stricter setter won't reject anything the readers produce. Writing [0, 255] through the alias round-trips. The offline suite, Ruff and the strict docs build pass locally.
Two optional notes:
- The #672 table pluralises only some per-annotation arrays (
channels,numbers,notes), whilesample,symbolandsubtypestay singular, soAnnotationwill end up with both styles. It's probably worth settling that convention beforenumbersandnotesare added. - Whole-number floats are stored as given (
np.array([1.0, 2.0])staysfloat64). The writer handles them, but converting to integers on assignment would make the stored value match what's written.
Ready to merge once CI is green.
|
Thanks for checking the reader output and write round trip. I agree we should settle the naming convention before adding I’d leave whole-number float arrays as supplied for now. |
## Summary Complete the annotation attribute naming step from #672 after #810 added `channels`. Add `sample_indices`, `symbols`, `subtypes`, `numbers`, `notes`, `label_codes`, `descriptions`, and `n_annotations` alongside the existing names. The new per-annotation names also work as constructor keywords, and the constructor rejects values supplied under both spellings. Each value alias refers to one stored value; the existing names remain writable with their current behavior. `n_annotations` is read-only and always returns the current length of `sample_indices`, even if the legacy `ann_len` value is stale. `sample_indices` makes clear that the array contains positions in a signal, not signal values. The new setters check the existing field rules without changing direct assignments through the legacy names. Unmapped symbols and descriptions from raw label codes can still be assigned through the new names and written losslessly. ## Verification - Full offline suite: 1,472 passed, 4 skipped, 22 deselected. - Focused alias suite: 43 passed. - Ruff format and lint passed. - Strict Sphinx HTML build passed.
Summary
Add
Annotation.channelsas a mutable alias for the existingchanarray. The constructor acceptschannelsas a keyword-only argument and rejects simultaneous values forchanandchannels. Both names use the same stored array, including after reads, copies, pickling, and writes.Assignments through the new spelling accept
Noneor a one-dimensional NumPy array of whole channel numbers from 0 through 255, matching the writer'schancontract. Direct assignment tochanretains its existing behavior. This is a small annotation naming step from #672; it leaves the more ambiguous record storage and signal-value names for their separate design decisions.Verification