diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 1b04d93b6f..cad2f2e337 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -124,10 +124,6 @@ This document explains the changes made to Iris for this release #. `@rcomer`_ fixed :meth:`~iris.cube.Cube.subset` to alway return ``None`` if no value match is found. (:pull:`4417`) -#. `@wjbenfold`_ resolved an issue that previously caused regridding with lazy - data to take significantly longer than with real data. Relevant benchmark - shows a time decrease from >10s to 625ms. (:issue:`4280`, :pull:`4400`) - #. `@wjbenfold`_ changed :meth:`iris.util.points_step` to stop it from warning when applied to a single point (:issue:`4250`, :pull:`4367`) @@ -140,6 +136,10 @@ This document explains the changes made to Iris for this release coordinate bounds using minimum and maximum for unordered coordinates, fixing :issue:`1528`. (:pull:`4315`) +#. `@wjbenfold`_ changed how a delayed unit conversion is performed on a cube + so that a cube with lazy data awaiting a unit conversion can be pickled. + (:issue:`4354 `, :pull:`4377`) + 💣 Incompatible Changes ======================= @@ -150,7 +150,10 @@ This document explains the changes made to Iris for this release 🚀 Performance Enhancements =========================== -#. N/A +#. `@wjbenfold`_ resolved an issue that previously caused regridding with lazy + data to take significantly longer than with real data. Benchmark + :class:`benchmarks.HorizontalChunkedRegridding` shows a time decrease + from >10s to 625ms. (:issue:`4280`, :pull:`4400`) 🔥 Deprecations diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 90acc021bc..3e1e98d12d 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -1051,9 +1051,7 @@ def convert_units(self, unit): old_unit = self.units new_unit = unit - # Define a delayed conversion operation (i.e. a callback). - def pointwise_convert(values): - return old_unit.convert(values, new_unit) + pointwise_convert = partial(old_unit.convert, other=new_unit) new_data = _lazy.lazy_elementwise( self.lazy_data(), pointwise_convert diff --git a/lib/iris/tests/test_pickling.py b/lib/iris/tests/test_pickling.py index e01f791d03..26247e795b 100644 --- a/lib/iris/tests/test_pickling.py +++ b/lib/iris/tests/test_pickling.py @@ -16,9 +16,10 @@ import pickle import cf_units +import numpy as np import iris -from iris._lazy_data import as_concrete_data +from iris._lazy_data import as_concrete_data, as_lazy_data class TestPickle(tests.IrisTest): @@ -76,6 +77,14 @@ def test_cube_with_coord_points(self): _, recon_cube = next(self.pickle_then_unpickle(cube)) self.assertEqual(recon_cube, cube) + def test_cube_with_deferred_unit_conversion(self): + real_data = np.arange(12.0).reshape((3, 4)) + lazy_data = as_lazy_data(real_data) + cube = iris.cube.Cube(lazy_data, units="m") + cube.convert_units("ft") + _, recon_cube = next(self.pickle_then_unpickle(cube)) + self.assertEqual(recon_cube, cube) + @tests.skip_data def test_cubelist_pickle(self): cubelist = iris.load(