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

#. N/A
#. `@bouweandela`_ and `@trexfeathers`_ (reviewer) updated :class:`~iris.cube.Cube`
comparison so equality is now possible between cubes with data containing a
:obj:`numpy.nan`. e.g. ``Cube([np.nan, 1.0]) == Cube([np.nan, 1.0])`` will now
evaluate to :obj:`True`, while previously this would have been :obj:`False`. (:pull:`5713`)


🚀 Performance Enhancements
Expand All @@ -113,6 +116,9 @@ This document explains the changes made to Iris for this release

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

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


🔥 Deprecations
===============
Expand Down
11 changes: 10 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,13 @@ 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 = bool(
np.allclose(
self.core_data(),
other.core_data(),
equal_nan=True,
)
)
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