MCPcopy Index your code
hub / github.com/pydata/xarray / test_chunk

Method test_chunk

xarray/tests/test_dataarray.py:954–990  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

952
953 @requires_dask
954 def test_chunk(self) -> None:
955 unblocked = DataArray(np.ones((3, 4)))
956 assert unblocked.chunks is None
957
958 blocked = unblocked.chunk()
959 assert blocked.chunks == ((3,), (4,))
960 first_dask_name = blocked.data.name
961
962 with pytest.warns(FutureWarning):
963 blocked = unblocked.chunk(chunks=((2, 1), (2, 2))) # type: ignore[arg-type]
964 assert blocked.chunks == ((2, 1), (2, 2))
965 assert blocked.data.name != first_dask_name
966
967 blocked = unblocked.chunk(chunks=(3, 3))
968 assert blocked.chunks == ((3,), (3, 1))
969 assert blocked.data.name != first_dask_name
970
971 with pytest.raises(ValueError):
972 blocked.chunk(chunks=(3, 3, 3))
973
974 # name doesn't change when rechunking by same amount
975 # this fails if ReprObject doesn't have __dask_tokenize__ defined
976 assert unblocked.chunk(2).data.name == unblocked.chunk(2).data.name
977
978 assert blocked.load().chunks is None
979
980 # Check that kwargs are passed
981 import dask.array as da
982
983 blocked = unblocked.chunk(name_prefix="testname_")
984 assert isinstance(blocked.data, da.Array)
985 assert "testname_" in blocked.data.name
986
987 # test kwargs form of chunks
988 blocked = unblocked.chunk(dim_0=3, dim_1=3)
989 assert blocked.chunks == ((3,), (3, 1))
990 assert blocked.data.name != first_dask_name
991
992 def test_isel(self) -> None:
993 assert_identical(self.dv[0], self.dv.isel(x=0))

Callers

nothing calls this directly

Calls 4

chunkMethod · 0.95
DataArrayClass · 0.90
chunkMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected