44# See LICENSE in the root of the repository for full licensing details.
55"""Integration tests for merging with dataless cubes."""
66
7+ import dask .array as da
78import numpy as np
89
910from iris .coords import AuxCoord , DimCoord
1011from iris .cube import Cube , CubeList
1112
1213
1314class TestMergeDataless :
14- def _testcube (self , z = 1 , name = "this" , dataless = False ):
15+ def _testcube (self , z = 1 , name = "this" , dataless = False , lazy = False ):
1516 # Create a testcube with a scalar Z coord, for merge testing.
17+ data = da .arange (3 ) if lazy else np .arange (3 )
1618 cube = Cube (
17- [ 1 , 2 , 3 ] ,
19+ data ,
1820 long_name = name ,
1921 dim_coords_and_dims = [(DimCoord ([0.0 , 1.0 , 2 ], long_name = "x" ), 0 )],
2022 aux_coords_and_dims = [(AuxCoord ([z ], long_name = "z" ), ())],
@@ -25,41 +27,39 @@ def _testcube(self, z=1, name="this", dataless=False):
2527
2628 def test_mixed_passthrough (self ):
2729 # Check that normal merge can handle dataless alongside dataful cubes.
28- cubes = CubeList (
29- [
30- self ._testcube (name = "this" , dataless = False ),
31- self ._testcube (name = "that" , dataless = True ),
32- ]
33- )
30+ cube_normal = self ._testcube (name = "this" , dataless = False )
31+ cube_dataless = self ._testcube (name = "that" , dataless = True )
32+ cubes = CubeList ([cube_normal , cube_dataless ])
33+
3434 result = cubes .merge ()
35+
3536 assert len (result ) == 2
3637 cube1 , cube2 = [result .extract_cube (name ) for name in ("this" , "that" )]
3738 assert not cube1 .is_dataless ()
3839 assert cube2 .is_dataless ()
3940
4041 def test_dataless_merge (self ):
4142 # Check that dataless cubes can be merged.
42- cubes = CubeList (
43- [
44- self ._testcube (z = 1 , dataless = True ),
45- self ._testcube (z = 2 , dataless = True ),
46- ]
47- )
43+ cube_1 = self ._testcube (z = 1 , dataless = True )
44+ cube_2 = self ._testcube (z = 2 , dataless = True )
45+ cubes = CubeList ([cube_1 , cube_2 ])
46+
4847 cube = cubes .merge_cube ()
48+
4949 assert cube .is_dataless ()
5050 assert np .all (cube .coord ("z" ).points == [1 , 2 ])
5151
5252 def test_dataless_dataful_merge (self ):
5353 # Check that dataless cubes can merge **with** regular ones.
54- # Check that dataless cubes can be merged correctly.
55- cubes = CubeList (
56- [
57- self ._testcube (z = 1 , dataless = False ),
58- self ._testcube (z = 2 , dataless = True ),
59- ]
60- )
54+ # Include checking that laziness is preserved.
55+ cube_normal = self ._testcube (z = 1 , dataless = False , lazy = True )
56+ cube_dataless = self ._testcube (z = 2 , dataless = True )
57+ cubes = CubeList ([cube_normal , cube_dataless ])
58+
6159 cube = cubes .merge_cube ()
60+
6261 assert not cube .is_dataless ()
62+ assert cube .has_lazy_data ()
6363 data_z1 , data_z2 = cube [0 ].data , cube [1 ].data
64- assert np .all (data_z1 == [1 , 2 , 3 ])
64+ assert np .all (data_z1 == [0 , 1 , 2 ])
6565 assert np .all (np .ma .getmaskarray (data_z2 ) == True ) # noqa: E712
0 commit comments