diff --git a/docs/iris/src/whatsnew/3.0.2.rst b/docs/iris/src/whatsnew/3.0.2.rst index 769b673a4c..44bce83643 100644 --- a/docs/iris/src/whatsnew/3.0.2.rst +++ b/docs/iris/src/whatsnew/3.0.2.rst @@ -42,6 +42,10 @@ This document explains the changes made to Iris for this release developers to easily disable `cirrus-ci`_ tasks. See :ref:`skipping Cirrus-CI tasks`. (:pull:`4019`) [``pre-v3.1.0``] + #. `@pp-mo`_ adjusted the use of :func:`dask.array.from_array` in :func:`iris._lazy_data.as_lazy_data`, to avoid + the dask 'test access'. This makes loading of netcdf files with a large number of variables significantly faster. + (:pull:`4135`) + Note that, the contributions labelled ``pre-v3.1.0`` are part of the forthcoming Iris v3.1.0 release, but require to be included in this patch release. diff --git a/lib/iris/_lazy_data.py b/lib/iris/_lazy_data.py index dcc0674fe6..c549cb4679 100644 --- a/lib/iris/_lazy_data.py +++ b/lib/iris/_lazy_data.py @@ -192,7 +192,9 @@ def as_lazy_data(data, chunks=None, asarray=False): if isinstance(data, ma.core.MaskedConstant): data = ma.masked_array(data.data, mask=data.mask) if not is_lazy_data(data): - data = da.from_array(data, chunks=chunks, asarray=asarray) + data = da.from_array( + data, chunks=chunks, asarray=asarray, meta=np.ndarray + ) return data diff --git a/lib/iris/tests/unit/lazy_data/test_co_realise_cubes.py b/lib/iris/tests/unit/lazy_data/test_co_realise_cubes.py index b7365a4316..2e3be105ed 100644 --- a/lib/iris/tests/unit/lazy_data/test_co_realise_cubes.py +++ b/lib/iris/tests/unit/lazy_data/test_co_realise_cubes.py @@ -71,12 +71,12 @@ def test_combined_access(self): cube_e = Cube(derived_e) co_realise_cubes(cube_a, cube_b, cube_c, cube_d, cube_e) # Though used more than once, the source data should only get fetched - # twice by dask. Once when dask performs an initial data access with - # no data payload to ascertain the metadata associated with the - # dask.array (this access is specific to dask 2+, see - # dask.array.utils.meta_from_array), and again when the whole data is - # accessed. - self.assertEqual(wrapped_array.access_count, 2) + # once by dask, when the whole data is accessed. + # This also ensures that dask does *not* perform an initial data + # access with no data payload to ascertain the metadata associated with + # the dask.array (this access is specific to dask 2+, + # see dask.array.utils.meta_from_array). + self.assertEqual(wrapped_array.access_count, 1) if __name__ == "__main__":