Skip to content

Commit 419025a

Browse files
committed
test .chunksizes
1 parent f892ef7 commit 419025a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

xarray/tests/test_dask.py

+37
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def test_chunk(self):
104104
assert rechunked.chunks == expected
105105
self.assertLazyAndIdentical(self.eager_var, rechunked)
106106

107+
expected_chunksizes = {
108+
dim: chunks for dim, chunks in zip(self.lazy_var.dims, expected)
109+
}
110+
assert rechunked.chunksizes == expected_chunksizes
111+
107112
def test_indexing(self):
108113
u = self.eager_var
109114
v = self.lazy_var
@@ -330,6 +335,38 @@ def setUp(self):
330335
self.data, coords={"x": range(4)}, dims=("x", "y"), name="foo"
331336
)
332337

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+
333370
def test_rechunk(self):
334371
chunked = self.eager_array.chunk({"x": 2}).chunk({"y": 2})
335372
assert chunked.chunks == ((2,) * 2, (2,) * 3)

0 commit comments

Comments
 (0)