Skip to content

Commit

Permalink
Add test for rechunking to a size string (#9117)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Jun 14, 2024
1 parent 380979f commit 211d313
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def copy(
Dims = Union[str, Collection[Hashable], "ellipsis", None]

# FYI in some cases we don't allow `None`, which this doesn't take account of.
T_ChunkDim: TypeAlias = Union[int, Literal["auto"], None, tuple[int, ...]]
# FYI the `str` is for a size string, e.g. "16MB", supported by dask.
T_ChunkDim: TypeAlias = Union[str, int, Literal["auto"], None, tuple[int, ...]]
# We allow the tuple form of this (though arguably we could transition to named dims only)
T_Chunks: TypeAlias = Union[T_ChunkDim, Mapping[Any, T_ChunkDim]]
T_NormalizedChunks = tuple[tuple[int, ...], ...]
Expand Down
5 changes: 4 additions & 1 deletion xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,16 @@ def setUp(self):
self.data, coords={"x": range(4)}, dims=("x", "y"), name="foo"
)

def test_chunk(self):
def test_chunk(self) -> None:
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))),
({"x": "16B"}, ((1, 1, 1, 1), (2, 2, 2))),
("16B", ((1, 1, 1, 1), (1,) * 6)),
("16MB", ((4,), (6,))),
]:
# Test DataArray
rechunked = self.lazy_array.chunk(chunks)
Expand Down

0 comments on commit 211d313

Please sign in to comment.