Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 7 additions & 1 deletion docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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
=======================
Expand All @@ -150,7 +154,9 @@ 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. Relevant benchmark
shows a time decrease from >10s to 625ms. (:issue:`4280`, :pull:`4400`)
Comment thread
bjlittle marked this conversation as resolved.
Outdated


🔥 Deprecations
Expand Down
4 changes: 1 addition & 3 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/iris/tests/test_pickling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down