MCPcopy
hub / github.com/pydata/xarray / test_chunk

Method test_chunk

xarray/tests/test_dask.py:349–381  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

347 )
348
349 def test_chunk(self) -> None:
350 test_cases: list[
351 tuple[int | str | dict[str, Any], tuple[tuple[int, ...], ...]]
352 ] = [
353 ({}, ((2, 2), (2, 2, 2))),
354 (3, ((3, 1), (3, 3))),
355 ({"x": 3, "y": 3}, ((3, 1), (3, 3))),
356 ({"x": 3}, ((3, 1), (2, 2, 2))),
357 ({"x": (3, 1)}, ((3, 1), (2, 2, 2))),
358 ({"x": "16B"}, ((1, 1, 1, 1), (2, 2, 2))),
359 ("16B", ((1, 1, 1, 1), (1,) * 6)),
360 ("16MB", ((4,), (6,))),
361 ]
362 for chunks, expected in test_cases:
363 # Test DataArray
364 rechunked = self.lazy_array.chunk(chunks)
365 assert rechunked.chunks == expected
366 self.assertLazyAndIdentical(self.eager_array, rechunked)
367
368 expected_chunksizes = dict(zip(self.lazy_array.dims, expected, strict=True))
369 assert rechunked.chunksizes == expected_chunksizes
370
371 # Test Dataset
372 lazy_dataset = self.lazy_array.to_dataset()
373 eager_dataset = self.eager_array.to_dataset()
374 expected_chunksizes = dict(zip(lazy_dataset.dims, expected, strict=True))
375 rechunked = lazy_dataset.chunk(chunks) # type: ignore[assignment]
376
377 # Dataset.chunks has a different return type to DataArray.chunks - see issue #5843
378 assert rechunked.chunks == expected_chunksizes
379 self.assertLazyAndIdentical(eager_dataset, rechunked)
380
381 assert rechunked.chunksizes == expected_chunksizes
382
383 def test_rechunk(self):
384 chunked = self.eager_array.chunk({"x": 2}).chunk({"y": 2})

Callers

nothing calls this directly

Calls 3

chunkMethod · 0.45
to_datasetMethod · 0.45

Tested by

no test coverage detected