From db2de7f33b4eddc31cc8f3a262ca70c8ba4f1b32 Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Tue, 15 May 2018 17:54:10 +0100 Subject: [PATCH] Tidy lazy_data imports in cube + coords modules. --- lib/iris/coords.py | 25 ++++++++++------------- lib/iris/cube.py | 9 ++++---- lib/iris/tests/unit/cube/test_CubeList.py | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/iris/coords.py b/lib/iris/coords.py index 464a3bfe2e9..781fa0babc0 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -38,10 +38,7 @@ from iris._data_manager import DataManager from iris._deprecation import warn_deprecated -from iris._lazy_data import (as_concrete_data as _lazy_as_concrete_data, - is_lazy_data as _lazy_is_lazy_data, - multidim_lazy_stack as lazy_multidim_stack, - lazy_elementwise as _lazy_elementwise) +import iris._lazy_data as _lazy import iris.aux_factory import iris.exceptions import iris.time @@ -556,7 +553,7 @@ def from_coord(cls, coord): return cls(**kwargs) def _sanitise_array(self, src, ndmin): - if _lazy_is_lazy_data(src): + if _lazy.is_lazy_data(src): # Lazy data : just ensure ndmin requirement. ndims_missing = ndmin - src.ndim if ndims_missing <= 0: @@ -674,7 +671,7 @@ def core_points(self): """ result = self._points_dm.core_data() - if not _lazy_is_lazy_data(result): + if not _lazy.is_lazy_data(result): result = result.view() return result @@ -687,7 +684,7 @@ def core_bounds(self): result = None if self.has_bounds(): result = self._bounds_dm.core_data() - if not _lazy_is_lazy_data(result): + if not _lazy.is_lazy_data(result): result = result.view() return result @@ -927,15 +924,15 @@ def pointwise_convert(values): return old_unit.convert(values, new_unit) if self.has_lazy_points(): - new_points = _lazy_elementwise(self.lazy_points(), - pointwise_convert) + new_points = _lazy.lazy_elementwise(self.lazy_points(), + pointwise_convert) else: new_points = self.units.convert(self.points, unit) self.points = new_points if self.has_bounds(): if self.has_lazy_bounds(): - new_bounds = _lazy_elementwise(self.lazy_bounds(), - pointwise_convert) + new_bounds = _lazy.lazy_elementwise(self.lazy_bounds(), + pointwise_convert) else: new_bounds = self.units.convert(self.bounds, unit) self.bounds = new_bounds @@ -1232,8 +1229,8 @@ def serialize(x): points = (float(lower) + float(upper)) * 0.5 # Create the new collapsed coordinate. - if _lazy_is_lazy_data(item): - bounds = lazy_multidim_stack(bounds) + if _lazy.is_lazy_data(item): + bounds = _lazy.multidim_lazy_stack(bounds) coord = self.copy(points=points, bounds=bounds) else: bounds = np.concatenate(bounds) @@ -1940,7 +1937,7 @@ def data(self, data): if data is None: raise ValueError('The data payload of a CellMeasure may not be ' 'None; it must be a numpy array or equivalent.') - if _lazy_is_lazy_data(data) and data.dtype.kind in 'biu': + if _lazy.is_lazy_data(data) and data.dtype.kind in 'biu': # Non-floating cell measures are not valid up to CF v1.7 msg = ('Cannot create cell measure with lazy data of type {}, as ' 'integer types are not currently supported.') diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 8c23b9394f8..b7066d92585 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -25,6 +25,7 @@ import six import collections +import copy from copy import deepcopy import datetime from functools import reduce @@ -41,8 +42,7 @@ import iris._concatenate import iris._constraints from iris._data_manager import DataManager -from iris._lazy_data import (lazy_elementwise as _lazy_elementwise, - co_realise_cubes as _lazy_co_realise_cubes) +import iris._lazy_data as _lazy import iris._merge import iris.analysis @@ -618,7 +618,7 @@ def realise_data(self): Cubes with non-lazy data are not affected. """ - _lazy_co_realise_cubes(*self) + _lazy.co_realise_cubes(*self) def _is_single_item(testee): @@ -911,7 +911,8 @@ def convert_units(self, unit): def pointwise_convert(values): return old_unit.convert(values, new_unit) - new_data = _lazy_elementwise(self.lazy_data(), pointwise_convert) + new_data = _lazy.lazy_elementwise(self.lazy_data(), + pointwise_convert) else: new_data = self.units.convert(self.data, unit) self.data = new_data diff --git a/lib/iris/tests/unit/cube/test_CubeList.py b/lib/iris/tests/unit/cube/test_CubeList.py index eb27bd5fce1..a7649b8b914 100644 --- a/lib/iris/tests/unit/cube/test_CubeList.py +++ b/lib/iris/tests/unit/cube/test_CubeList.py @@ -308,7 +308,7 @@ def test_realise_data(self): # _lazy_data.co_realise_cubes. mock_cubes_list = [mock.Mock(ident=count) for count in range(3)] test_cubelist = CubeList(mock_cubes_list) - call_patch = self.patch('iris.cube._lazy_co_realise_cubes') + call_patch = self.patch('iris.cube._lazy.co_realise_cubes') test_cubelist.realise_data() # Check it was called once, passing cubes as *args. self.assertEqual(call_patch.call_args_list,