Skip to content

Commit

Permalink
refactor: better error message for unsorted spans
Browse files Browse the repository at this point in the history
    Changed from AssertionError to SparvErrorMessage, that also prints the first unsorted index pair and their values.
  • Loading branch information
kod-kristoff authored and MartinHammarstedt committed Jun 10, 2024
1 parent d74f77e commit 4013331
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sparv/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ def _write_single_annotation(
if is_span:
if not isinstance(values, list):
values = list(values)
# Make sure that spans are sorted
assert all(values[i] <= values[i + 1] for i in range(len(values) - 1)), "Annotation spans must be sorted."
# Validate that spans are sorted
for i in range(len(values) - 1):
if values[i] > values[i + 1]:
raise SparvErrorMessage(
f"Annotation spans must be sorted. values[{i}]={values[i]} > values[{i+1}]={values[i+1]}",
module="core.io",
function="_write_single_annotation",
)
# Always save spans with decimal tuples
if values and not isinstance(values[0][0], tuple):
values = [((v[0],), (v[1],)) for v in values]
Expand Down

0 comments on commit 4013331

Please sign in to comment.