Skip to content

Add remaining readable Annotation field aliases - #811

Merged
tompollard merged 2 commits into
mainfrom
feature/annotation-field-aliases
Nov 30, 2026
Merged

tompollard merged 2 commits into
mainfrom
feature/annotation-field-aliases

Conversation

@tompollard

@tompollard tompollard commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

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.

@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, this completes the annotation names from #672 using the plural convention, including descriptions. Each pair shares one stored value, both spellings are rejected together in the constructor, sample_indices can replace the positional sample, and failed assignments leave the existing field untouched. I assigned every field of the real annotation files in sample-data (.atr, .qrs, .wabp, .wqrs, read with symbols only and with all label fields) back through the new names, 85 assignments with no failures, so the stricter setters accept what the readers produce. Unmapped symbols from raw codes still write losslessly. The offline suite, Ruff and the strict docs build pass locally.

One change I'd make before merging: n_annotations is a writable alias of ann_len with no validation, and it can go stale. On read_annotations("sample-data/100.atr", stop=2000), trimming sample and the other fields to 3 entries through the existing names leaves n_annotations == 8, and n_annotations = 99 and n_annotations = "5" are both accepted. Unlike a record, an annotation always has its positions, so the count is always len(sample_indices), and the declared-count reasoning from #744 doesn't apply. Could n_annotations be a read-only property returning len(self.sample), leaving ann_len as is?

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I agree. n_annotations now returns len(self.sample) and is read-only; ann_len keeps its existing behavior. I added a regression test that trims sample through the old name, then makes ann_len stale, and confirms that n_annotations still reports the current count. It also checks that assigning to n_annotations raises AttributeError. The 43 focused alias tests, Ruff, and the strict docs build pass. This is in commit 8fa4be5.

@tompollard
tompollard merged commit 53db997 into main Nov 30, 2026
19 checks passed
@tompollard
tompollard deleted the feature/annotation-field-aliases branch November 30, 2026 22:12
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