Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Unreleased
**Reject aux notes that can't be written in wrann**
``wrann`` now raises a ``ValueError`` if an ``aux_note`` is longer than 255 characters or contains characters outside Latin-1, instead of writing a corrupt annotation file. A longer note used to be read back as many extra annotations, and other characters were silently replaced.

**Allow None for annotations without notes in wrann**
``wrann`` now accepts ``None`` in ``aux_note`` for annotations without a note, as the docstring says, and writes it the same way as an empty string. It used to raise a ``TypeError``.

Version 4.3.1 (Feb 2026)
-----------------------------

Expand Down
3 changes: 3 additions & 0 deletions src/wfdb/io/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ def check_field(self, field):
# The string fields
elif field in ["symbol", "description", "aux_note"]:
uniq_elements = set(item)
# None means no note, the same as an empty string
if field == "aux_note":
uniq_elements.discard(None)

for e in uniq_elements:
if not isinstance(e, str_types):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,23 @@ def test_aux_note_rejected(temp_path, aux_note, match):
write_dir=temp_path,
)
assert not os.path.exists(os.path.join(temp_path, "bad_aux.atr"))


def test_aux_note_none(temp_path):
"""None in aux_note means no note, as for an empty string."""
for name, aux_note in [("none", [None, "(VT", None]), ("empty", ["", "(VT", ""])]:
wfdb.wrann(
name,
"atr",
np.array([1, 5, 9]),
symbol=["N", "N", "V"],
aux_note=aux_note,
write_dir=temp_path,
)
ann = wfdb.rdann(os.path.join(temp_path, "none"), "atr")
assert ann.aux_note == ["", "(VT", ""]
with (
open(os.path.join(temp_path, "none.atr"), "rb") as f1,
open(os.path.join(temp_path, "empty.atr"), "rb") as f2,
):
assert f1.read() == f2.read()
Loading