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
2 changes: 0 additions & 2 deletions docs/iris/src/whatsnew/2.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ Iris 2.2 Dependency updates
Bugs Fixed
==========

* Cube equality of boolean data is now handled correctly.

* The bug has been fixed that prevented printing time coordinates with bounds
when the time coordinate was measured on a long interval (that is, ``months``
or ``years``).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Cube equality of boolean data is now handled correctly.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Cube data equality testing (and hence cube equality) now uses a more relaxed
tolerance : This means that some cubes may now test 'equal' that previously
did not.
Previously, Iris compared cube data arrays using "abs(a - b) < 1.e-8".
We now apply the default operation of :func:`numpy.allclose` instead,
which is equivalent to "abs(a - b) < (1.e-8 + 1.e-5 * b)".
46 changes: 46 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1905,5 +1905,51 @@ def test_preserves_lazy(self):
self.assertArrayAllClose(cube.data, real_data_ft)


class Test__eq__data(tests.IrisTest):
"""Partial cube equality testing, for data type only."""
def test_data_float_eq(self):
cube1 = Cube([1.0])
cube2 = Cube([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
# "rtol=1e-8", and this example would *fail*.
val2 = np.array(1.0 + 1.e-6, dtype=np.float32)
cube1 = Cube([val1])
cube2 = Cube([val2])
self.assertNotEqual(val1, val2)
self.assertTrue(cube1 == cube2)

def test_data_float_not_eq(self):
val1 = 1.0
val2 = 1.0 + 1.e-4
cube1 = Cube([1.0, val1])
cube2 = Cube([1.0, val2])
self.assertFalse(cube1 == cube2)

def test_data_int_eq(self):
cube1 = Cube([1, 2, 3])
cube2 = Cube([1, 2, 3])
self.assertTrue(cube1 == cube2)

def test_data_int_not_eq(self):
cube1 = Cube([1, 2, 3])
cube2 = Cube([1, 2, 0])
self.assertFalse(cube1 == cube2)

# NOTE: since numpy v1.18, boolean array subtract is deprecated.
def test_data_bool_eq(self):
cube1 = Cube([True, False])
cube2 = Cube([True, False])
self.assertTrue(cube1 == cube2)

def test_data_bool_not_eq(self):
cube1 = Cube([True, False])
cube2 = Cube([True, True])
self.assertFalse(cube1 == cube2)


if __name__ == '__main__':
tests.main()
2 changes: 1 addition & 1 deletion requirements/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cartopy
#conda: proj4<6
cf-units>=2
cftime
dask[array]>=1.1.0 #conda: dask>=1.1.0
dask[array]>=1.2.0 #conda: dask>=1.2.0
matplotlib>=2,<3
netcdf4
numpy>=1.14
Expand Down