Skip to content

Fix formatting bug for zero values #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
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: 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