Repository navigation
Keep every annotation field in Annotation.apply_range - #661
tompollard wants to merge 4 commits into
Conversation
apply_range filtered sample, label_store, subtype, chan, num and aux_note, but not symbol or description, which then no longer matched sample. It also failed with a TypeError on an annotation read by rdann with the default return_label_elements, where label_store is None. Filter every per-annotation field that is set, keeping arrays as arrays and lists as lists, and leave fields that are not set as None. Calling apply_range on an rdann result now gives the same fields as reading only that range. rdann's own results are unchanged for every annotation file in sample-data, with and without sampfrom, sampto and shift_samps.
tompollard
left a comment
There was a problem hiding this comment.
One issue to address before merging: apply_range() now slices the per-annotation fields, but it leaves contained_labels unchanged if the annotation was previously summarized. That makes the summary disagree with the filtered annotations.
For example, starting with wfdb.rdann("sample-data/100", "atr", summarize_labels=True) and then calling apply_range(sampfrom=600000, sampto=620000) leaves 71 annotations, while contained_labels still counts all 2,274 original annotations. Reading that range directly with rdann(..., sampfrom=600000, sampto=620000, summarize_labels=True) gives a summary count of 71.
Could apply_range() refresh or clear contained_labels when it is present, and add a test for this sequence? The new per-annotation field handling otherwise looks good; the focused offline annotation tests passed.
apply_range kept contained_labels as it was, so after summarize_labels=True the summary still counted every annotation, not only those kept. It now summarizes the labels again when there is a summary, giving the same contained_labels as reading only that range.
|
Thanks, fixed in the latest commit, after merging When the annotation has a label summary, New |
Follow-up to #654, from the review there.
Annotation.apply_rangefilteredsample,label_store,subtype,chan,numandaux_note, but notsymbolordescription. It also indexedlabel_storeunconditionally, so on record100:apply_rangenow filters every per-annotation field that is set (sample,label_store,symbol,description,subtype,chan,numandaux_note), keeping arrays as arrays and lists as lists, and leaves fields that areNoneas they are. So callingapply_rangeon anrdannresult gives the same fields as reading only that range withrdann.rdanncallsapply_rangeitself whensampfromis given, so I compared every field ofrdannresults before and after this change: for every annotation file insample-data, with no range,sampfrom,sampto, both,shift_samps, and all three label elements (66 reads), the results are identical.Testing:
test_apply_range_keeps_every_field_consistent, for the defaultrdannresult and with all three label elements, checks thatapply_rangegives the same fields asrdann(..., sampfrom=600000, sampto=620000), and that unset fields stayNone. Both cases fail onmain.uv run pytest -m "not network": 493 passed.uv run pytest -m network: 18 passed.ruff format --check,ruff check, the docs build andtowncrier build --draftpass. Changelog entry added inchangelog.d/.@tompollard 🟥 red 🦥 sloth