Repository navigation
Reject sampto=0 in rdann, and summarize no annotations - #660
Merged
Merged
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #654.
sampto=0.rdanntreatedsampto=0as no limit when reading the file, butAnnotation.apply_range, which #654 now calls wheneversampfromis given, treats it as a real limit. On record100:rdann(sampto=0)ValueErrorrdann(sampfrom=10, sampto=0)ValueErrorrdrecord(sampfrom=10, sampto=0)ValueErrorValueErrorcheck_read_inputsnow raisesValueError("sampto must be greater than sampfrom")wheneversamptois notNoneand not greater thansampfrom, asrdrecorddoes. Thesamptodocstring now says so.sampto=0was not documented as meaning no limit, and nothing in the package or its tests used it.summarize_labels=Truewith no annotations.rdann("sample-data/100", "atr", sampfrom=10**9, summarize_labels=True)failed withKeyError: 'n_occurrences'fromget_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 withsampfromalone. For every annotation file insample-data, read with each oflabel_store,symbolanddescription(33 reads),contained_labelsis unchanged, including its column types.Testing:
test_rdann_sampto_must_be_after_sampfrom(4 cases, two of them withsampto=0) andtest_rdann_summarize_labels_without_annotations. Thesampto=0cases and the summary test fail onmain.uv run pytest -m "not network": 496 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