Skip to content

Commit 211d313

Browse files
authored
Add test for rechunking to a size string (#9117)
1 parent 380979f commit 211d313

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

xarray/core/types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def copy(
182182
Dims = Union[str, Collection[Hashable], "ellipsis", None]
183183

184184
# FYI in some cases we don't allow `None`, which this doesn't take account of.
185-
T_ChunkDim: TypeAlias = Union[int, Literal["auto"], None, tuple[int, ...]]
185+
# FYI the `str` is for a size string, e.g. "16MB", supported by dask.
186+
T_ChunkDim: TypeAlias = Union[str, int, Literal["auto"], None, tuple[int, ...]]
186187
# We allow the tuple form of this (though arguably we could transition to named dims only)
187188
T_Chunks: TypeAlias = Union[T_ChunkDim, Mapping[Any, T_ChunkDim]]
188189
T_NormalizedChunks = tuple[tuple[int, ...], ...]

xarray/tests/test_dask.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,16 @@ def setUp(self):
337337
self.data, coords={"x": range(4)}, dims=("x", "y"), name="foo"
338338
)
339339

340-
def test_chunk(self):
340+
def test_chunk(self) -> None:
341341
for chunks, expected in [
342342
({}, ((2, 2), (2, 2, 2))),
343343
(3, ((3, 1), (3, 3))),
344344
({"x": 3, "y": 3}, ((3, 1), (3, 3))),
345345
({"x": 3}, ((3, 1), (2, 2, 2))),
346346
({"x": (3, 1)}, ((3, 1), (2, 2, 2))),
347+
({"x": "16B"}, ((1, 1, 1, 1), (2, 2, 2))),
348+
("16B", ((1, 1, 1, 1), (1,) * 6)),
349+
("16MB", ((4,), (6,))),
347350
]:
348351
# Test DataArray
349352
rechunked = self.lazy_array.chunk(chunks)

0 commit comments

Comments
 (0)