Skip to content
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

fix module __eq__ #35

Merged
merged 1 commit into from
May 13, 2023
Merged
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
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