Repository navigation
Write custom annotation symbols of more than one character - #669
Conversation
custom_triplet_bytes called ord() on the whole symbol, and computed the note's length for a one-character symbol, so wrann failed with a TypeError for custom labels with 2 or 3 character symbols. Build the note as a string first. Files with one-character symbols are unchanged. Fixes #411.
tompollard
left a comment
There was a problem hiding this comment.
I found two issues to address before merging 6da26ce:
-
custom_triplet_bytes()can write an unreadable annotation file when the encoded note is longer than the one-byte AUX length (src/wfdb/io/annotation.py:1595). I reproduced this with custom symbolPV2and a 249-character description: the note length is 256, which becomes 0 when converted tou1.wrann()returns successfully, butrdann()raisesIndexErroron the file. Please reject an oversized note before writing and test the 255/256-byte boundary. -
The PR says it fixes #411, but validation still rejects symbols longer than three characters (
src/wfdb/io/annotation.py:504).wrann(..., symbol=["ABCD"], custom_labels=[(42, "ABCD", "beat")])raisesValueError. The issue explicitly describes multi-character mnemonics without a three-character limit. Could this support longer symbols within the annotation note's capacity, or narrow the PR's scope and leave #411 open?
The 43 focused offline annotation tests and all 18 PR checks pass; they do not cover these cases.
Lift the 3-character limit on symbols, which the WFDB format does not have; symbols must still be non-empty and have no whitespace. A custom label is written as a note whose length is stored in one byte, so raise a ValueError, before any file is written, when the note is longer than 255 Latin-1 characters or cannot be encoded, instead of writing a file that rdann cannot read.
|
Thanks, both fixed in 95dd3b6.
One-character custom labels still give a file byte-identical to |
tompollard
left a comment
There was a problem hiding this comment.
Re-reviewed commit 95dd3b6. Both findings from my earlier review are resolved: custom symbols longer than three characters now round-trip, and custom label notes over 255 bytes raise ValueError before creating a file. The 48 focused offline annotation tests pass. I found no remaining blocker. Docs and style checks pass; the test matrix is still running.
Fixes #411.
wrannfailed withTypeError: ord() expected a characterfor a custom label whose symbol has more than one character, althoughrdannreads such symbols.custom_triplet_bytescalledord()on the whole symbol, and computed the note's length byte for a one-character symbol. It now builds the note ("<label_store> <symbol> <description>") as a string and encodes it as Latin-1, asaux_noteis.rdanncouldn't read.wrannnow raises aValueErrorbefore writing anything, as it already does for a longaux_note. It does the same for characters that Latin-1 can't hold.For one-character symbols the bytes are the same as before: a file with two custom labels and
fswritten with this branch is identical to one written withmain.Testing
main.pytest -m "not network": all pass. Ruff passes.@tompollard 🟥 red 🦥 sloth · aspen