Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/pyrecest/filters/track_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from .abstract_filter import AbstractFilter
from .abstract_multitarget_tracker import AbstractMultitargetTracker
from .abstract_tracker_with_logging import _coerce_bool_flag
from .kalman_filter import KalmanFilter

PredictorFn = Callable[..., None]
Expand Down Expand Up @@ -182,12 +183,15 @@ def __init__(
self.associator = associator
self.n_init = n_init
self.max_misses = max_misses
self.allow_births = bool(allow_births)
self.allow_births = _coerce_bool_flag(allow_births, "allow_births")
self.confirm_condition = confirm_condition
self.delete_condition = delete_condition
self.track_metadata_initializer = track_metadata_initializer
self.extract_confirmed_only = bool(extract_confirmed_only)
self.keep_history = bool(keep_history)
self.extract_confirmed_only = _coerce_bool_flag(
extract_confirmed_only,
"extract_confirmed_only",
)
self.keep_history = _coerce_bool_flag(keep_history, "keep_history")

self.tracks: List[Track] = []
self._next_track_id = 0
Expand Down
31 changes: 31 additions & 0 deletions tests/filters/test_track_manager_boolean_controls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest

import numpy as np

from pyrecest.filters.track_manager import TrackManager


class TrackManagerBooleanControlTest(unittest.TestCase):
def test_boolean_controls_accept_numpy_boolean_scalars(self):
manager = TrackManager(
allow_births=np.bool_(False),
extract_confirmed_only=np.bool_(False),
keep_history=np.bool_(False),
)

self.assertFalse(manager.allow_births)
self.assertFalse(manager.extract_confirmed_only)
self.assertFalse(manager.keep_history)

def test_boolean_controls_reject_truthy_non_boolean_values(self):
for control in ("allow_births", "extract_confirmed_only", "keep_history"):
with self.subTest(control=control):
with self.assertRaisesRegex(ValueError, rf"{control} must be"):
TrackManager(**{control: "False"})

def test_boolean_controls_reject_numeric_values(self):
for control in ("allow_births", "extract_confirmed_only", "keep_history"):
for value in (0, 1, np.array(0), np.array(1)):
with self.subTest(control=control, value=value):
with self.assertRaisesRegex(ValueError, rf"{control} must be"):
TrackManager(**{control: value})
Loading