Skip to content

Commit

Permalink
fix type handling for clocktime and step_size (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebachmeier authored Oct 31, 2024
1 parent 11b19a8 commit a2481a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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**

Expand Down
19 changes: 16 additions & 3 deletions src/vivarium/framework/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit a2481a2

Please # to comment.