From d1ae5ca598ea7d972a5a7cecc6be316435ef1323 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Tue, 18 Jun 2024 17:45:13 +0200 Subject: [PATCH 1/2] Do not realize cell measures and ancillary variables in concatenate --- lib/iris/_concatenate.py | 4 ++-- .../concatenate/test_concatenate.py | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/iris/_concatenate.py b/lib/iris/_concatenate.py index 927ee9989c..c42f5bf8b9 100644 --- a/lib/iris/_concatenate.py +++ b/lib/iris/_concatenate.py @@ -1145,7 +1145,7 @@ def _build_cell_measures(self): # Concatenate the data together. dim = dims.index(self.axis) data = [ - skton.signature.cell_measures_and_dims[i].coord.data + skton.signature.cell_measures_and_dims[i].coord.core_data() for skton in skeletons ] data = concatenate_arrays(tuple(data), axis=dim) @@ -1185,7 +1185,7 @@ def _build_ancillary_variables(self): # Concatenate the data together. dim = dims.index(self.axis) data = [ - skton.signature.ancillary_variables_and_dims[i].coord.data + skton.signature.ancillary_variables_and_dims[i].coord.core_data() for skton in skeletons ] data = concatenate_arrays(tuple(data), axis=dim) diff --git a/lib/iris/tests/integration/concatenate/test_concatenate.py b/lib/iris/tests/integration/concatenate/test_concatenate.py index 13110781dc..063ae76d83 100644 --- a/lib/iris/tests/integration/concatenate/test_concatenate.py +++ b/lib/iris/tests/integration/concatenate/test_concatenate.py @@ -12,6 +12,7 @@ import iris.tests as tests # isort:skip import cf_units +import dask.array as da import numpy as np from iris._concatenate import _DerivedCoordAndDims, concatenate @@ -157,6 +158,16 @@ def test_ignore_diff_cell_measure(self): self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (4, 2)) + def test_lazy_cell_measure(self): + cube_a = self.create_cube() + cube_a.cell_measure("volume").data = da.array([0, 15]) + cube_b = cube_a.copy() + cube_b.coord("time").points = [12, 18] + + result = concatenate([cube_a, cube_b]) + assert len(result) == 1 + assert result[0].cell_measure("volume").has_lazy_data() + class Test_cubes_with_ancillary_variables(tests.IrisTest): def create_cube(self): @@ -194,6 +205,16 @@ def test_ignore_diff_ancillary_variables(self): self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (4, 2)) + def test_lazy_ancillary_variables(self): + cube_a = self.create_cube() + cube_a.ancillary_variable("quality").data = da.array([0, 15]) + cube_b = cube_a.copy() + cube_b.coord("time").points = [12, 18] + + result = concatenate([cube_a, cube_b]) + assert len(result) == 1 + assert result[0].ancillary_variable("quality").has_lazy_data() + class Test_cubes_with_derived_coord(tests.IrisTest): def create_cube(self): From e35420299a5dc7d2b66b59c434ec44087b8fe8c1 Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Wed, 19 Jun 2024 09:59:14 +0200 Subject: [PATCH 2/2] Add whatsnew entry --- docs/src/whatsnew/latest.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 3b7b0e92a9..897c4c147a 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -65,6 +65,9 @@ This document explains the changes made to Iris for this release #. `@bouweandela`_ made :meth:`iris.cube.Cube.rolling_window` work with lazy data. (:pull:`5795`) +#. `@bouweandela`_ updated :meth:`iris.cube.CubeList.concatenate` so it keeps + ancillary variables and cell measures lazy. (:pull:`6010`) + 🔥 Deprecations ===============