Skip to content

Commit 252c1f9

Browse files
Use stricter typing for eval_stack used by the FormulaEngine (#162)
... now that `None` values are getting converted to `NaN` before they get stored in the `eval_stack`. Signed-off-by: Sahas Subramanian <[email protected]>
2 parents a2c5a4b + e866605 commit 252c1f9

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/frequenz/sdk/timeseries/logical_meter/_formula_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async def _apply(self) -> Sample:
126126
RuntimeError: if some samples didn't arrive, or if formula application
127127
failed.
128128
"""
129-
eval_stack: List[Optional[float]] = []
129+
eval_stack: List[float] = []
130130
ready_metrics, pending = await asyncio.wait(
131131
[
132132
asyncio.create_task(fetcher.fetch_next(), name=name)

src/frequenz/sdk/timeseries/logical_meter/_formula_steps.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __repr__(self) -> str:
3131
"""
3232

3333
@abstractmethod
34-
def apply(self, eval_stack: List[Optional[float]]) -> None:
34+
def apply(self, eval_stack: List[float]) -> None:
3535
"""Apply a formula operation on the eval_stack.
3636
3737
Args:
@@ -50,7 +50,7 @@ def __repr__(self) -> str:
5050
"""
5151
return "+"
5252

53-
def apply(self, eval_stack: List[Optional[float]]) -> None:
53+
def apply(self, eval_stack: List[float]) -> None:
5454
"""Extract two values from the stack, add them, push the result back in.
5555
5656
Args:
@@ -73,7 +73,7 @@ def __repr__(self) -> str:
7373
"""
7474
return "-"
7575

76-
def apply(self, eval_stack: List[Optional[float]]) -> None:
76+
def apply(self, eval_stack: List[float]) -> None:
7777
"""Extract two values from the stack, subtract them, push the result back in.
7878
7979
Args:
@@ -96,7 +96,7 @@ def __repr__(self) -> str:
9696
"""
9797
return "*"
9898

99-
def apply(self, eval_stack: List[Optional[float]]) -> None:
99+
def apply(self, eval_stack: List[float]) -> None:
100100
"""Extract two values from the stack, multiply them, push the result back in.
101101
102102
Args:
@@ -119,7 +119,7 @@ def __repr__(self) -> str:
119119
"""
120120
return "/"
121121

122-
def apply(self, eval_stack: List[Optional[float]]) -> None:
122+
def apply(self, eval_stack: List[float]) -> None:
123123
"""Extract two values from the stack, divide them, push the result back in.
124124
125125
Args:
@@ -168,7 +168,7 @@ def __repr__(self) -> str:
168168
"""
169169
return f"avg({', '.join(repr(f) for f in self._fetchers)})"
170170

171-
def apply(self, eval_stack: List[Optional[float]]) -> None:
171+
def apply(self, eval_stack: List[float]) -> None:
172172
"""Calculate average of given metrics, push the average to the eval_stack.
173173
174174
Args:
@@ -243,7 +243,7 @@ def __repr__(self) -> str:
243243
"""
244244
return self._name
245245

246-
def apply(self, eval_stack: List[Optional[float]]) -> None:
246+
def apply(self, eval_stack: List[float]) -> None:
247247
"""Push the latest value from the stream into the evaluation stack.
248248
249249
Args:
@@ -262,4 +262,4 @@ def apply(self, eval_stack: List[Optional[float]]) -> None:
262262
else:
263263
eval_stack.append(float("NaN"))
264264
else:
265-
eval_stack.append(self._next_value.value)
265+
eval_stack.append(next_value)

0 commit comments

Comments
 (0)