@@ -104,6 +104,11 @@ def test_chunk(self):
104
104
assert rechunked .chunks == expected
105
105
self .assertLazyAndIdentical (self .eager_var , rechunked )
106
106
107
+ expected_chunksizes = {
108
+ dim : chunks for dim , chunks in zip (self .lazy_var .dims , expected )
109
+ }
110
+ assert rechunked .chunksizes == expected_chunksizes
111
+
107
112
def test_indexing (self ):
108
113
u = self .eager_var
109
114
v = self .lazy_var
@@ -330,6 +335,38 @@ def setUp(self):
330
335
self .data , coords = {"x" : range (4 )}, dims = ("x" , "y" ), name = "foo"
331
336
)
332
337
338
+ def test_chunk (self ):
339
+ for chunks , expected in [
340
+ ({}, ((2 , 2 ), (2 , 2 , 2 ))),
341
+ (3 , ((3 , 1 ), (3 , 3 ))),
342
+ ({"x" : 3 , "y" : 3 }, ((3 , 1 ), (3 , 3 ))),
343
+ ({"x" : 3 }, ((3 , 1 ), (2 , 2 , 2 ))),
344
+ ({"x" : (3 , 1 )}, ((3 , 1 ), (2 , 2 , 2 ))),
345
+ ]:
346
+ # Test DataArray
347
+ rechunked = self .lazy_array .chunk (chunks )
348
+ assert rechunked .chunks == expected
349
+ self .assertLazyAndIdentical (self .eager_array , rechunked )
350
+
351
+ expected_chunksizes = {
352
+ dim : chunks for dim , chunks in zip (self .lazy_array .dims , expected )
353
+ }
354
+ assert rechunked .chunksizes == expected_chunksizes
355
+
356
+ # Test Dataset
357
+ lazy_dataset = self .lazy_array .to_dataset ()
358
+ eager_dataset = self .eager_array .to_dataset ()
359
+ expected_chunksizes = {
360
+ dim : chunks for dim , chunks in zip (lazy_dataset .dims , expected )
361
+ }
362
+ rechunked = lazy_dataset .chunk (chunks )
363
+
364
+ # Dataset.chunks has a different return type to DataArray.chunks - see issue #5843
365
+ assert rechunked .chunks == expected_chunksizes
366
+ self .assertLazyAndIdentical (eager_dataset , rechunked )
367
+
368
+ assert rechunked .chunksizes == expected_chunksizes
369
+
333
370
def test_rechunk (self ):
334
371
chunked = self .eager_array .chunk ({"x" : 2 }).chunk ({"y" : 2 })
335
372
assert chunked .chunks == ((2 ,) * 2 , (2 ,) * 3 )
0 commit comments