Skip to content

Commit e66d5eb

Browse files
address review comments
1 parent d3671dc commit e66d5eb

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

docs/src/whatsnew/dev.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ This document explains the changes made to Iris for this release
7171
coordinate's direction is reversed. (:issue:`3249`, :issue:`423`,
7272
:issue:`4078`, :issue:`3756`, :pull:`4466`)
7373

74+
#. `@stephenworsley`_ aligned the behaviour of :obj:`~iris.coords.Cell` equality
75+
to match :obj:`~iris.coords.Coord` equality with respect to NaN values.
76+
Two NaN valued Cells are now considered equal. This fixes :issue:`4681` and
77+
causes NaN valued scalar coordinates to be able to merge be preserved during
78+
cube merging. (:pull:`4701`)
79+
7480

7581
💣 Incompatible Changes
7682
=======================

lib/iris/coords.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,24 +1352,27 @@ def __eq__(self, other):
13521352
compared.
13531353
13541354
"""
1355+
1356+
def nan_equality(x, y):
1357+
return (
1358+
isinstance(x, (float, np.number))
1359+
and np.isnan(x)
1360+
and isinstance(y, (float, np.number))
1361+
and np.isnan(y)
1362+
)
1363+
13551364
if isinstance(other, (int, float, np.number)) or hasattr(
13561365
other, "timetuple"
13571366
):
13581367
if self.bound is not None:
13591368
return self.contains_point(other)
1360-
elif isinstance(other, (float, np.number)) and np.isnan(other):
1361-
return isinstance(self.point, (float, np.number)) and np.isnan(
1362-
self.point
1363-
)
1369+
elif nan_equality(self.point, other):
1370+
return True
13641371
else:
13651372
return self.point == other
13661373
elif isinstance(other, Cell):
1367-
if isinstance(other.point, (float, np.number)) and np.isnan(
1368-
other.point
1369-
):
1370-
return isinstance(self.point, (float, np.number)) and np.isnan(
1371-
self.point
1372-
)
1374+
if nan_equality(self.point, other.point):
1375+
return True
13731376
return (self.point == other.point) and (
13741377
self.bound == other.bound or self.bound == other.bound[::-1]
13751378
)

0 commit comments

Comments
 (0)