Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ This document explains the changes made to Iris for this release
馃挘 Incompatible Changes
=======================

#. N/A
#. `@bouweandela`_ updated cube comparison so cubes with data containing a
:obj:`numpy.nan` are now considered equal (:pull:`5713`)
Comment thread
bouweandela marked this conversation as resolved.
Outdated


馃殌 Performance Enhancements
Expand All @@ -113,6 +114,8 @@ This document explains the changes made to Iris for this release

#. `@bouweandela`_ made comparing coordinates and arrays to themselves faster. (:pull:`5691`)

#. `@bouweandela`_ made comparing cubes to themselves faster. (:pull:`5713`)


馃敟 Deprecations
===============
Expand Down
9 changes: 8 additions & 1 deletion lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -3824,6 +3824,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 Expand Up @@ -3862,7 +3865,11 @@ def __eq__(self, other):
if result:
# TODO: why do we use allclose() here, but strict equality in
# _DimensionalMetadata (via util.array_equal())?
result = da.allclose(self.core_data(), other.core_data()).compute()
result = da.allclose(
self.core_data(),
other.core_data(),
equal_nan=True,
).compute()
Comment thread
trexfeathers marked this conversation as resolved.
Outdated
return result

# Must supply __ne__, Python does not defer to __eq__ for negative equality
Expand Down
9 changes: 9 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2841,11 +2841,20 @@ def test_unit_multiply(self):
class Test__eq__data(tests.IrisTest):
"""Partial cube equality testing, for data type only."""

def test_cube_identical_to_itself(self):
cube = Cube([1.0])
self.assertTrue(cube == cube)

def test_data_float_eq(self):
cube1 = Cube([1.0])
cube2 = Cube([1.0])
self.assertTrue(cube1 == cube2)

def test_data_float_nan_eq(self):
cube1 = Cube([np.nan, 1.0])
cube2 = Cube([np.nan, 1.0])
self.assertTrue(cube1 == cube2)

def test_data_float_eqtol(self):
val1 = np.array(1.0, dtype=np.float32)
# NOTE: Since v2.3, Iris uses "allclose". Prior to that we used
Expand Down