Skip to content

Commit

Permalink
Faster trivial equality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bouweandela committed Jan 11, 2024
1 parent b11af45 commit 6e2e81f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ def __repr__(self):
return self.summary(shorten=True)

def __eq__(self, other):
if other is self:
return True

# Note: this method includes bounds handling code, but it only runs
# within Coord type instances, as only these allow bounds to be set.

Expand Down
3 changes: 3 additions & 0 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,9 @@ def _deepcopy(self, memo, data=None):

# START OPERATOR OVERLOADS
def __eq__(self, other):
if other is self:
return True

result = NotImplemented

if isinstance(other, Cube):
Expand Down
2 changes: 2 additions & 0 deletions lib/iris/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def array_equal(array1, array2, withnans=False):
This function maintains laziness when called; it does not realise data.
See more at :doc:`/userguide/real_and_lazy_data`.
"""
if withnans and (array1 is array2):
return True

def normalise_array(array):
if not is_lazy_data(array):
Expand Down

0 comments on commit 6e2e81f

Please sign in to comment.