Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Fix: Parameters: Constant eq float error #27

Merged
merged 2 commits into from
Sep 2, 2024
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
7 changes: 7 additions & 0 deletions src/faebryk/library/Constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from typing import Self, SupportsAbs

import numpy as np

from faebryk.core.parameter import Parameter, _resolved
from faebryk.libs.units import Quantity

Expand Down Expand Up @@ -32,6 +34,11 @@ def __eq__(self, other) -> bool:
if not isinstance(other, Constant):
return False

try:
return np.allclose(self.value, other.value)
except (TypeError, np.exceptions.DTypePromotionError):
...

return self.value == other.value

def __hash__(self) -> int:
Expand Down
3 changes: 3 additions & 0 deletions test/core/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ def __preinit__(self) -> None:
r = r.get_most_narrow()
self.assertIsInstance(r, Range, f"{type(r)}")

def test_units(self):
self.assertEqual(Constant(1e-9 * P.F), 1 * P.nF)


if __name__ == "__main__":
unittest.main()