diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index e799f5dbd9..592c713b4d 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -46,6 +46,10 @@ This document explains the changes made to Iris for this release #. `@trexfeathers`_ and `@pp-mo`_ made Iris' use of the `netCDF4`_ library thread-safe. (:pull:`5095`) +#. `@ESadek-MO`_ removed check and error raise for saving + cubes with masked :class:`iris.coords.CellMeasure`. + (:issue:`5147`, :pull:`5181`) + 💣 Incompatible Changes ======================= diff --git a/lib/iris/fileformats/netcdf/saver.py b/lib/iris/fileformats/netcdf/saver.py index e5d3bf2cc7..f7f4864f9e 100644 --- a/lib/iris/fileformats/netcdf/saver.py +++ b/lib/iris/fileformats/netcdf/saver.py @@ -1933,16 +1933,6 @@ def _create_generic_cf_array_var( # Check if this is a dim-coord. is_dimcoord = cube is not None and element in cube.dim_coords - if isinstance(element, iris.coords.CellMeasure): - # Disallow saving of *masked* cell measures. - # NOTE: currently, this is the only functional difference in - # variable creation between an ancillary and a cell measure. - if iris.util.is_masked(data): - # We can't save masked points properly, as we don't maintain - # a fill_value. (Load will not record one, either). - msg = "Cell measures with missing data are not supported." - raise ValueError(msg) - if is_dimcoord: # By definition of a CF-netCDF coordinate variable this # coordinate must be 1-D and the name of the CF-netCDF variable diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py index 6fa9e9e096..93a1537ea4 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py @@ -1051,38 +1051,5 @@ def test_geo_cs(self): self._test(coord_system, expected) -class Test__create_cf_cell_measure_variable(tests.IrisTest): - # Saving of masked data is disallowed. - - # Attribute is substituted in test_Saver__lazy. - array_lib = np - - def setUp(self): - self.cube = stock.lat_lon_cube() - self.names_map = ["latitude", "longitude"] - masked_array = self.array_lib.ma.masked_array( - [0, 1, 2], mask=[True, False, True] - ) - self.cm = iris.coords.CellMeasure(masked_array, var_name="cell_area") - self.cube.add_cell_measure(self.cm, data_dims=0) - self.exp_emsg = "Cell measures with missing data are not supported." - - def test_masked_data__insitu(self): - # Test that the error is raised in the right place. - with self.temp_filename(".nc") as nc_path: - saver = Saver(nc_path, "NETCDF4") - with self.assertRaisesRegex(ValueError, self.exp_emsg): - saver._create_generic_cf_array_var( - self.cube, self.names_map, self.cm - ) - - def test_masked_data__save_pipeline(self): - # Test that the right error is raised by the saver pipeline. - with self.temp_filename(".nc") as nc_path: - with Saver(nc_path, "NETCDF4") as saver: - with self.assertRaisesRegex(ValueError, self.exp_emsg): - saver.write(self.cube) - - if __name__ == "__main__": tests.main() diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_Saver__lazy.py b/lib/iris/tests/unit/fileformats/netcdf/test_Saver__lazy.py index eab09b9e4f..53e1f9a652 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_Saver__lazy.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_Saver__lazy.py @@ -82,12 +82,6 @@ class Test_check_attribute_compliance__exception_handling( pass -class Test__create_cf_cell_measure_variable( - LazyMixin, test_Saver.Test__create_cf_cell_measure_variable -): - pass - - class TestStreamed(tests.IrisTest): def setUp(self): self.cube = stock.simple_2d()