From e909aa958dae3765f4cc26595162934c7bc0b7a3 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Tue, 19 May 2020 00:20:59 -0700 Subject: [PATCH] fix equality for things which may or may not be numpy arrays --- fatamorgana/basic.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/fatamorgana/basic.py b/fatamorgana/basic.py index c49da9b..17de875 100644 --- a/fatamorgana/basic.py +++ b/fatamorgana/basic.py @@ -1321,11 +1321,19 @@ class GridRepetition: return size def __eq__(self, other: Any) -> bool: - return isinstance(other, type(self)) and \ - self.a_count == other.a_count and \ - self.b_count == other.b_count and \ - self.a_vector == other.a_vector and \ - self.b_vector == other.b_vector + if not isinstance(other, type(self)): + return False + if self.a_count != other.a_count or self.b_count != other.b_count: + return False + if any(self.a_vector[ii] != other.a_vector[ii] for ii in range(2)): + return False + if self.b_vector is None and other.b_vector is None: + return True + if self.b_vector is None or other.b_vector is None: + return False + if any(self.b_vector[ii] != other.b_vector[ii] for ii in range(2)): + return False + return True def __repr__(self) -> str: return 'GridRepetition: ({} : {} | {} : {})'.format(self.a_count, self.a_vector,