@@ -736,9 +736,7 @@ def test_to_zarr_chunks_per_shard(self):
736736 ds2 = xarray .Dataset ({'foo' : (('x' , 'y' ), np .zeros ((12 , 10 )))})
737737 beam_ds2 = xbeam .Dataset .from_xarray (ds2 , {'x' : 6 , 'y' : 5 })
738738 with beam .Pipeline () as p :
739- p |= beam_ds2 .to_zarr (
740- temp_dir , zarr_chunks_per_shard = {'x' : 3 , ...: 1 }
741- )
739+ p |= beam_ds2 .to_zarr (temp_dir , zarr_chunks_per_shard = {'x' : 3 , ...: 1 })
742740 opened , chunks = xbeam .open_zarr (temp_dir )
743741 xarray .testing .assert_identical (ds2 , opened )
744742 self .assertEqual (chunks , {'x' : 2 , 'y' : 5 })
@@ -786,7 +784,8 @@ def test_to_zarr_chunks_per_shard(self):
786784 beam_ds = xbeam .Dataset .from_xarray (ds , {'x' : 6 })
787785 with self .assertRaisesRegex (
788786 ValueError ,
789- r'cannot write a dataset with chunks .*zarr_chunks_per_shard=.* which do not evenly divide' ,
787+ r'cannot write a dataset with chunks .*zarr_chunks_per_shard=.* which'
788+ r' do not evenly divide' ,
790789 ):
791790 beam_ds .to_zarr (temp_dir , zarr_chunks_per_shard = {'x' : 5 })
792791
@@ -1002,6 +1001,27 @@ def test_map_blocks_new_split_vars_fails(self):
10021001 ):
10031002 source_ds .map_blocks (func )
10041003
1004+ def test_map_blocks_non_unique (self ):
1005+ source = xarray .Dataset ({'foo' : ('x' , np .arange (8 ))})
1006+ source_ds = xbeam .Dataset .from_xarray (source , {'x' : 4 })
1007+ with self .assertRaisesRegex (
1008+ ValueError ,
1009+ "dimension 'x' has multiple chunks on the source dataset, and "
1010+ 'therefore must be included in the result of map_blocks, but is not '
1011+ 'in the new template:' ,
1012+ ):
1013+ source_ds .map_blocks (lambda ds : ds .mean ('x' ))
1014+
1015+ def test_map_blocks_inconsistent_chunks_error (self ):
1016+ source = xarray .Dataset ({'foo' : ('x' , np .arange (8 ))})
1017+ source_ds = xbeam .Dataset .from_xarray (source , {'x' : 4 })
1018+ with self .assertRaisesWithLiteralMatch (
1019+ ValueError ,
1020+ "dimension 'x' has 2 chunks on the source dataset and 8 in the result "
1021+ 'of map_blocks' ,
1022+ ):
1023+ source_ds .map_blocks (lambda ds : ds , chunks = {'x' : 1 })
1024+
10051025
10061026class RechunkingTest (test_util .TestCase ):
10071027
0 commit comments