Skip to content

Commit 91dcdee

Browse files
committed
Add laziness tests for calculus 'delta_cube' and 'differentiate'.
1 parent dbdcd41 commit 91dcdee

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/iris/tests/test_analysis_calculus.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ def test_delta_coord_lookup(self):
4444
assert delta_coord == delta.coord(coord)
4545
assert coord == cube.coord(delta_coord)
4646

47+
@pytest.mark.parametrize("is_lazy", [True, False], ids=["is_lazy", "not_lazy"])
48+
def test_delta_lazypreserving(self, is_lazy):
49+
cube = iris.cube.Cube(np.arange(10), standard_name="air_temperature")
50+
# Add a coordinate with a lot of metadata.
51+
coord = iris.coords.DimCoord(
52+
np.arange(10),
53+
long_name="projection_x_coordinate",
54+
var_name="foo",
55+
attributes={"source": "testing"},
56+
units="m",
57+
coord_system=iris.coord_systems.OSGB(),
58+
)
59+
cube.add_dim_coord(coord, 0)
60+
if is_lazy:
61+
cube.data = cube.lazy_data()
62+
delta = iris.analysis.calculus.cube_delta(cube, "projection_x_coordinate")
63+
assert delta.has_lazy_data() == is_lazy
64+
4765

4866
class TestDeltaAndMidpoint:
4967
def _simple_filename(self, suffix):
@@ -303,6 +321,13 @@ def test_diff_wrt_lat(self):
303321
approx_data=True,
304322
)
305323

324+
@pytest.mark.parametrize("is_lazy", [True, False], ids=["is_lazy", "not_lazy"])
325+
def test_diff_lazypreserving(self, is_lazy):
326+
if is_lazy:
327+
self.cube.data = self.cube.lazy_data()
328+
t = iris.analysis.calculus.differentiate(self.cube, "longitude")
329+
assert t.has_lazy_data() == is_lazy
330+
306331

307332
class TestCalculusSimple2:
308333
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)