Skip to content

Commit

Permalink
fix module __eq__
Browse files Browse the repository at this point in the history
  • Loading branch information
ahalev committed May 13, 2023
1 parent 4cbed1b commit b6f7a88
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/pymgrid/modules/base/base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,23 @@ def __eq__(self, other):
if type(self) != type(other):
return NotImplemented

diff = [(k1, v1, v2) for (k1, v1), (k2, v2) in zip(self.__dict__.items(), other.__dict__.items()) if
((hasattr(v1, "any") and not np.allclose(v1, v2)) or (not hasattr(v1, "any") and v1 != v2))]
def are_equal(v1, v2):
try:
_are_equal = bool(v1 == v2)
if _are_equal:
return True
except ValueError:
pass

try:
return np.allclose(v1, v2)
except (ValueError, TypeError):
return False

diff = [
(k1, v1, v2) for (k1, v1), (k2, v2) in zip(self.__dict__.items(), other.__dict__.items())
if not are_equal(v1, v2)
]

return len(diff) == 0

Expand Down

0 comments on commit b6f7a88

Please sign in to comment.