Skip to content

Commit

Permalink
Tidy lazy_data imports in cube + coords modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
pp-mo committed May 15, 2018
1 parent 8ff5de7 commit db2de7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
25 changes: 11 additions & 14 deletions lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.')
Expand Down
9 changes: 5 additions & 4 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import six

import collections
import copy
from copy import deepcopy
import datetime
from functools import reduce
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/unit/cube/test_CubeList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit db2de7f

Please sign in to comment.