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
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

## Bug Fixes

- Fix formatting issue for `Quantity` objects with zero values.

<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
2 changes: 1 addition & 1 deletion src/frequenz/sdk/timeseries/_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def __format__(self, __format_spec: str) -> str:
return f"{self._base_value:.{precision}f}"

abs_value = abs(self._base_value)
exponent = math.floor(math.log10(abs_value))
exponent = math.floor(math.log10(abs_value)) if abs_value else 0
unit_place = exponent - exponent % 3
if unit_place < min(self._exponent_unit_map):
unit = self._exponent_unit_map[min(self._exponent_unit_map.keys())]
Expand Down
5 changes: 5 additions & 0 deletions tests/timeseries/test_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def test_string_representation() -> None:
assert f"{Fz1(1.024445, exponent=-12)}" == "0 Hz"
assert f"{Fz2(1.024445, exponent=-12)}" == "0 Hz"

assert f"{Fz1(0)}" == "0 Hz"

assert f"{Fz1(-20)}" == "-20 Hz"
assert f"{Fz1(-20000)}" == "-20 kHz"


def test_addition_subtraction() -> None:
"""Test the addition and subtraction of the quantities."""
Expand Down