Skip to content

Add channels alias to Annotation - #810

Merged
tompollard merged 1 commit into
mainfrom
feature/annotation-channels
Nov 30, 2026
Merged

tompollard merged 1 commit into
mainfrom
feature/annotation-channels

Conversation

@tompollard

Copy link
Copy Markdown
Member

Summary

Add Annotation.channels as a mutable alias for the existing chan array. The constructor accepts channels as a keyword-only argument and rejects simultaneous values for chan and channels. Both names use the same stored array, including after reads, copies, pickling, and writes.

Assignments through the new spelling accept None or a one-dimensional NumPy array of whole channel numbers from 0 through 255, matching the writer's chan contract. Direct assignment to chan retains 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

  • Full offline suite: 1,444 passed, 4 skipped, 22 deselected.
  • Ruff format and lint passed.
  • Strict Sphinx HTML build passed.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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), while sample, symbol and subtype stay singular, so Annotation will end up with both styles. It's probably worth settling that convention before numbers and notes are added.
  • Whole-number floats are stored as given (np.array([1.0, 2.0]) stays float64). 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.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks for checking the reader output and write round trip. I agree we should settle the naming convention before adding numbers or notes; I’ll keep that discussion on #672 rather than expand this PR.

I’d leave whole-number float arrays as supplied for now. channels and chan are intended to expose the same stored array, and coercing on assignment would silently replace a caller’s array. The writer already accepts these values and encodes them as integer channel numbers. If we want annotation arrays normalized in memory, I think that should be a separate, consistent decision across the annotation fields.

@tompollard
tompollard merged commit 64be9c6 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the feature/annotation-channels branch November 30, 2026 21:00
tompollard added a commit that referenced this pull request Nov 30, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant