diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 63eaf70b..bb448297 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,9 +1,10 @@ -**3.0.16 - 10/31/24** +**3.0.16 - 10/30/24** - Bugfix to prevent a LookupTable from changing order of the value columns - Fix mypy errors in vivarium/framework/lookup/table.py - Typing changes in vivarium/framework/lookup/interpolation.py - Fix broken build from LayeredConfigTree typing + - Fix type handling for clock and step size in vivarium/framework/event.py **3.0.15 - 10/24/24** diff --git a/src/vivarium/framework/event.py b/src/vivarium/framework/event.py index d5805970..075f2d81 100644 --- a/src/vivarium/framework/event.py +++ b/src/vivarium/framework/event.py @@ -30,7 +30,7 @@ from __future__ import annotations from collections.abc import Callable -from datetime import datetime +from datetime import datetime, timedelta from typing import TYPE_CHECKING, Any, NamedTuple import pandas as pd @@ -115,11 +115,24 @@ def emit(self, index: pd.Index[int], user_data: dict[str, Any] | None = None) -> """ if not user_data: user_data = {} + + clock = self.manager.clock() + step_size = self.manager.step_size() + event_time: ClockTime + if isinstance(clock, int) and isinstance(step_size, int): + event_time = clock + step_size + elif isinstance(clock, datetime) and isinstance(step_size, timedelta): + event_time = clock + step_size + else: + raise ValueError( + f"Clock ({type(clock)}) and step size ({type(step_size)}) are not compatible." + ) + e = Event( index, user_data, - self.manager.clock() + self.manager.step_size(), # type: ignore[operator, arg-type] - self.manager.step_size(), + event_time, + step_size, ) for priority_bucket in self.listeners: diff --git a/src/vivarium/types.py b/src/vivarium/types.py index cc902455..5d813e31 100644 --- a/src/vivarium/types.py +++ b/src/vivarium/types.py @@ -19,8 +19,8 @@ float, int, ] -# todo need to use TypeVars here +# TODO: [MIC-5481] need to use TypeVars here Time = Union[pd.Timestamp, datetime] Timedelta = Union[pd.Timedelta, timedelta] -ClockTime = Union[Time, Number] -ClockStepSize = Union[Timedelta, Number] +ClockTime = Union[Time, int] +ClockStepSize = Union[Timedelta, int]