Skip to content

Commit

Permalink
test .chunksizes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Oct 28, 2021
1 parent f892ef7 commit 419025a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def test_chunk(self):
assert rechunked.chunks == expected
self.assertLazyAndIdentical(self.eager_var, rechunked)

expected_chunksizes = {
dim: chunks for dim, chunks in zip(self.lazy_var.dims, expected)
}
assert rechunked.chunksizes == expected_chunksizes

def test_indexing(self):
u = self.eager_var
v = self.lazy_var
Expand Down Expand Up @@ -330,6 +335,38 @@ def setUp(self):
self.data, coords={"x": range(4)}, dims=("x", "y"), name="foo"
)

def test_chunk(self):
for chunks, expected in [
({}, ((2, 2), (2, 2, 2))),
(3, ((3, 1), (3, 3))),
({"x": 3, "y": 3}, ((3, 1), (3, 3))),
({"x": 3}, ((3, 1), (2, 2, 2))),
({"x": (3, 1)}, ((3, 1), (2, 2, 2))),
]:
# Test DataArray
rechunked = self.lazy_array.chunk(chunks)
assert rechunked.chunks == expected
self.assertLazyAndIdentical(self.eager_array, rechunked)

expected_chunksizes = {
dim: chunks for dim, chunks in zip(self.lazy_array.dims, expected)
}
assert rechunked.chunksizes == expected_chunksizes

# Test Dataset
lazy_dataset = self.lazy_array.to_dataset()
eager_dataset = self.eager_array.to_dataset()
expected_chunksizes = {
dim: chunks for dim, chunks in zip(lazy_dataset.dims, expected)
}
rechunked = lazy_dataset.chunk(chunks)

# Dataset.chunks has a different return type to DataArray.chunks - see issue #5843
assert rechunked.chunks == expected_chunksizes
self.assertLazyAndIdentical(eager_dataset, rechunked)

assert rechunked.chunksizes == expected_chunksizes

def test_rechunk(self):
chunked = self.eager_array.chunk({"x": 2}).chunk({"y": 2})
assert chunked.chunks == ((2,) * 2, (2,) * 3)
Expand Down

0 comments on commit 419025a

Please sign in to comment.