@@ -640,8 +640,10 @@ def counting_get(*args, **kwargs):
640
640
641
641
def test_duplicate_dims (self ):
642
642
data = np .random .normal (size = (4 , 4 ))
643
- arr = DataArray (data , dims = ("x" , "x" ))
644
- chunked_array = arr .chunk ({"x" : 2 })
643
+ with pytest .warns (UserWarning , match = "Duplicate dimension" ):
644
+ arr = DataArray (data , dims = ("x" , "x" ))
645
+ with pytest .warns (UserWarning , match = "Duplicate dimension" ):
646
+ chunked_array = arr .chunk ({"x" : 2 })
645
647
assert chunked_array .chunks == ((2 , 2 ), (2 , 2 ))
646
648
assert chunked_array .chunksizes == {"x" : (2 , 2 )}
647
649
@@ -1364,7 +1366,8 @@ def test_map_blocks_ds_transformations(func, map_ds):
1364
1366
@pytest .mark .parametrize ("obj" , [make_da (), make_ds ()])
1365
1367
def test_map_blocks_da_ds_with_template (obj ):
1366
1368
func = lambda x : x .isel (x = [1 ])
1367
- template = obj .isel (x = [1 , 5 , 9 ])
1369
+ # a simple .isel(x=[1, 5, 9]) puts all those in a single chunk.
1370
+ template = xr .concat ([obj .isel (x = [i ]) for i in [1 , 5 , 9 ]], dim = "x" )
1368
1371
with raise_if_dask_computes ():
1369
1372
actual = xr .map_blocks (func , obj , template = template )
1370
1373
assert_identical (actual , template )
@@ -1395,15 +1398,16 @@ def test_map_blocks_roundtrip_string_index():
1395
1398
1396
1399
def test_map_blocks_template_convert_object ():
1397
1400
da = make_da ()
1401
+ ds = da .to_dataset ()
1402
+
1398
1403
func = lambda x : x .to_dataset ().isel (x = [1 ])
1399
- template = da .to_dataset ().isel (x = [1 , 5 , 9 ])
1404
+ template = xr . concat ([ da .to_dataset ().isel (x = [i ]) for i in [ 1 , 5 , 9 ]], dim = "x" )
1400
1405
with raise_if_dask_computes ():
1401
1406
actual = xr .map_blocks (func , da , template = template )
1402
1407
assert_identical (actual , template )
1403
1408
1404
- ds = da .to_dataset ()
1405
1409
func = lambda x : x .to_dataarray ().isel (x = [1 ])
1406
- template = ds .to_dataarray ().isel (x = [1 , 5 , 9 ])
1410
+ template = xr . concat ([ ds .to_dataarray ().isel (x = [i ]) for i in [ 1 , 5 , 9 ]], dim = "x" )
1407
1411
with raise_if_dask_computes ():
1408
1412
actual = xr .map_blocks (func , ds , template = template )
1409
1413
assert_identical (actual , template )
@@ -1429,7 +1433,7 @@ def test_map_blocks_errors_bad_template(obj):
1429
1433
xr .map_blocks (
1430
1434
lambda a : a .isel (x = [1 ]).assign_coords (x = [120 ]), # assign bad index values
1431
1435
obj ,
1432
- template = obj .isel (x = [1 , 5 , 9 ]),
1436
+ template = xr . concat ([ obj .isel (x = [i ]) for i in [ 1 , 5 , 9 ]], dim = "x" ),
1433
1437
).compute ()
1434
1438
1435
1439
0 commit comments