diff --git a/docs/iris/src/whatsnew/contributions_2.0/incompatiblechange_2017-Aug-29_fill_value_save_arg.txt b/docs/iris/src/whatsnew/contributions_2.0/incompatiblechange_2017-Aug-29_fill_value_save_arg.txt index d773ea87beb..90aaa5a6f05 100644 --- a/docs/iris/src/whatsnew/contributions_2.0/incompatiblechange_2017-Aug-29_fill_value_save_arg.txt +++ b/docs/iris/src/whatsnew/contributions_2.0/incompatiblechange_2017-Aug-29_fill_value_save_arg.txt @@ -1 +1 @@ -* When saving a cube or list of cubes, a fill value or list of fill values can be specified via a new `fill_value` argument. If a list is supplied, each fill value will be applied to each cube in turn. If a `fill_value` argument is not specified, the default fill value for the file format and the cube's data type will be used. Fill values are no longer taken from the cube's `data` attribute when it is a masked array. +* When saving a cube or list of cubes in netCDF, a fill value or list of fill values can be specified via a new `fill_value` argument. If a list is supplied, each fill value will be applied to each cube in turn. If a `fill_value` argument is not specified, the default fill value for the file format and the cube's data type will be used. Fill values are no longer taken from the cube's `data` attribute when it is a masked array. diff --git a/lib/iris/fileformats/netcdf.py b/lib/iris/fileformats/netcdf.py index d569e3c9142..76d44c90d67 100644 --- a/lib/iris/fileformats/netcdf.py +++ b/lib/iris/fileformats/netcdf.py @@ -48,6 +48,7 @@ from iris.aux_factory import HybridHeightFactory, HybridPressureFactory, \ OceanSigmaZFactory, OceanSigmaFactory, OceanSFactory, OceanSg1Factory, \ OceanSg2Factory +import iris.config import iris.coord_systems import iris.coords import iris.cube diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py index c75e1302503..3ab339b21e2 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_Saver.py @@ -413,7 +413,8 @@ def test_mask_lazy_fill_value(self): self.assertTrue(var[index].mask) def test_mask_lazy_default_fill_value(self): - # Test that masked lazy data saves correctly when given a fill value. + # Test that masked lazy data saves correctly using the default fill + # value. index = (1, 1) cube = self._make_cube('>f4', masked_index=index, lazy=True) with self._netCDF_var(cube) as var: @@ -477,6 +478,15 @@ def test_masked_byte_default_fill_value(self): with self._netCDF_var(cube): pass + def test_masked_byte_fill_value_passed(self): + # Test that no warning is raised when saving masked byte data with a + # fill value supplied if the the data does not contain the fill_value. + fill_value = 100 + cube = self._make_cube('>i1', masked_value=2) + with self._warning_check('contains masked byte data', False): + with self._netCDF_var(cube, fill_value=fill_value): + pass + class _Common__check_attribute_compliance(object): def setUp(self): diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_save.py b/lib/iris/tests/unit/fileformats/netcdf/test_save.py index b08c3b7137d..6aa8dcffc03 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_save.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_save.py @@ -158,7 +158,7 @@ def test_None(self): self.assertIs(None, kwargs['fill_value']) def test_single(self): - # Test that when a signle value is passed as the fill_value argument, + # Test that when a single value is passed as the fill_value argument, # that value is passed to each call to Saver.write cubes = self._make_cubes() fill_value = 12345.