diff --git a/docs/iris/src/whatsnew/2.2.rst b/docs/iris/src/whatsnew/2.2.rst index 61a52e3784..1eff99ecb4 100644 --- a/docs/iris/src/whatsnew/2.2.rst +++ b/docs/iris/src/whatsnew/2.2.rst @@ -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``). diff --git a/docs/iris/src/whatsnew/contributions_2.3.0/bugfix_2019-Oct-02_boolean_data_compare.txt b/docs/iris/src/whatsnew/contributions_2.3.0/bugfix_2019-Oct-02_boolean_data_compare.txt new file mode 100644 index 0000000000..332e60c863 --- /dev/null +++ b/docs/iris/src/whatsnew/contributions_2.3.0/bugfix_2019-Oct-02_boolean_data_compare.txt @@ -0,0 +1 @@ +* Cube equality of boolean data is now handled correctly. diff --git a/docs/iris/src/whatsnew/contributions_2.3.0/newfeature_2019-Oct-02_cube_equality_tolerance.txt b/docs/iris/src/whatsnew/contributions_2.3.0/newfeature_2019-Oct-02_cube_equality_tolerance.txt new file mode 100644 index 0000000000..7a0c15f421 --- /dev/null +++ b/docs/iris/src/whatsnew/contributions_2.3.0/newfeature_2019-Oct-02_cube_equality_tolerance.txt @@ -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)". diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index 7d02f2d0ca..ea2c3c2dfe 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -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() diff --git a/requirements/core.txt b/requirements/core.txt index eb7d39ca5d..48ee3f1dfd 100644 --- a/requirements/core.txt +++ b/requirements/core.txt @@ -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