From 7085ce7ea27d7b6988a4e15cafc1ef85f1e06d5f Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Mon, 29 Jun 2026 11:54:08 +0200 Subject: [PATCH 1/2] Normalize sequence association top-k validation errors --- src/pyrecest/filters/sequence_association.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pyrecest/filters/sequence_association.py b/src/pyrecest/filters/sequence_association.py index d769e8737..c2f75489a 100644 --- a/src/pyrecest/filters/sequence_association.py +++ b/src/pyrecest/filters/sequence_association.py @@ -365,7 +365,10 @@ def _validate_cost(value: object, name: str) -> float: def _validate_positive_integer(value: object, name: str) -> int: message = f"{name} must be a positive integer" - value_array = np.asarray(value) + try: + value_array = np.asarray(value) + except (TypeError, ValueError) as exc: + raise ValueError(message) from exc if value_array.ndim != 0 or value_array.dtype == np.bool_: raise ValueError(message) From 9060b24cb75d77449803f36d2807af16586449d7 Mon Sep 17 00:00:00 2001 From: Florian Pfaff <6773539+FlorianPfaff@users.noreply.github.com> Date: Mon, 29 Jun 2026 11:54:50 +0200 Subject: [PATCH 2/2] Add top-k validation regression --- ...st_sequence_association_top_k_bad_input.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/filters/test_sequence_association_top_k_bad_input.py diff --git a/tests/filters/test_sequence_association_top_k_bad_input.py b/tests/filters/test_sequence_association_top_k_bad_input.py new file mode 100644 index 000000000..78dfdf799 --- /dev/null +++ b/tests/filters/test_sequence_association_top_k_bad_input.py @@ -0,0 +1,20 @@ +import pytest + +from pyrecest.filters import SequenceAssociationNode, solve_top_k_viterbi_sequence_associations + + +class UncoercibleScalar: + def __array__(self, dtype=None): + del dtype + raise TypeError("cannot convert") + + +def test_top_k_terminal_paths_reports_value_error_for_uncoercible_scalar(): + frames = [[SequenceAssociationNode(0, 0)]] + + with pytest.raises(ValueError, match="top_k_terminal_paths must be a positive integer"): + solve_top_k_viterbi_sequence_associations( + frames, + lambda _previous, _current, _context: 0.0, + top_k_terminal_paths=UncoercibleScalar(), + )