Skip to content

Reject sampto=0 in rdann, and summarize no annotations - #660

Merged
tompollard merged 1 commit into
mainfrom
rdann-range-follow-up
Nov 23, 2026
Merged

tompollard merged 1 commit into
mainfrom
rdann-range-follow-up

Conversation

@tompollard

Copy link
Copy Markdown
Member

Follow-up to #654.

sampto=0. rdann treated sampto=0 as no limit when reading the file, but Annotation.apply_range, which #654 now calls whenever sampfrom is given, treats it as a real limit. On record 100:

Call Before After
rdann(sampto=0) 2274 annotations ValueError
rdann(sampfrom=10, sampto=0) 0 annotations ValueError
rdrecord(sampfrom=10, sampto=0) ValueError ValueError

check_read_inputs now raises ValueError("sampto must be greater than sampfrom") whenever sampto is not None and not greater than sampfrom, as rdrecord does. The sampto docstring now says so. sampto=0 was not documented as meaning no limit, and nothing in the package or its tests used it.

summarize_labels=True with no annotations. rdann("sample-data/100", "atr", sampfrom=10**9, summarize_labels=True) failed with KeyError: 'n_occurrences' from get_contained_labels, which only created that column while adding counts, so not when there were none. The column is now created first. #654 made this reachable with sampfrom alone. For every annotation file in sample-data, read with each of label_store, symbol and description (33 reads), contained_labels is unchanged, including its column types.

Testing:

  • New test_rdann_sampto_must_be_after_sampfrom (4 cases, two of them with sampto=0) and test_rdann_summarize_labels_without_annotations. The sampto=0 cases and the summary test fail on main.
  • uv run pytest -m "not network": 496 passed. uv run pytest -m network: 18 passed.
  • ruff format --check, ruff check, the docs build and towncrier build --draft pass. Changelog entry added in changelog.d/.

@tompollard 🟥 red 🦥 sloth

rdann treated sampto=0 as no limit when reading the file, but apply_range,
which #654 now uses whenever sampfrom is given, treats it as a real limit.
So rdann(sampto=0) returned every annotation, and rdann(sampfrom=10,
sampto=0) returned none, without an error. rdann now raises a ValueError
whenever sampto is not greater than sampfrom, as rdrecord does.

With summarize_labels=True, get_contained_labels failed with KeyError:
'n_occurrences' when there were no annotations, for example when sampfrom
is after the last one, since the column was only created while adding
counts. It is now created first. The result is unchanged for every
annotation file in sample-data.
@tompollard

Copy link
Copy Markdown
Member Author

Reviewed ed09986. LGTM: sampto=0 now raises a consistent range error, and empty annotation summaries retain the n_occurrences column. I found no blocking issues. All 32 focused annotation tests and all CI checks pass.

@tompollard
tompollard merged commit f8de935 into main Nov 23, 2026
18 checks passed
@tompollard
tompollard deleted the rdann-range-follow-up branch November 23, 2026 16:39
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