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

Method test_full_like_dask

xarray/tests/test_variable.py:2854–2883  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2852
2853 @requires_dask
2854 def test_full_like_dask(self) -> None:
2855 orig = Variable(
2856 dims=("x", "y"), data=[[1.5, 2.0], [3.1, 4.3]], attrs={"foo": "bar"}
2857 ).chunk(dict(x=(1, 1), y=(2,)))
2858
2859 def check(actual, expect_dtype, expect_values):
2860 assert actual.dtype == expect_dtype
2861 assert actual.shape == orig.shape
2862 assert actual.dims == orig.dims
2863 assert actual.attrs == orig.attrs
2864 assert actual.chunks == orig.chunks
2865 assert_array_equal(actual.values, expect_values)
2866
2867 check(full_like(orig, 2), orig.dtype, np.full_like(orig.values, 2))
2868 # override dtype
2869 check(
2870 full_like(orig, True, dtype=bool),
2871 bool,
2872 np.full_like(orig.values, True, dtype=bool),
2873 )
2874
2875 # Check that there's no array stored inside dask
2876 # (e.g. we didn't create a numpy array and then we chunked it!)
2877 dsk = full_like(orig, 1).data.dask
2878 for v in dsk.values():
2879 if isinstance(v, tuple):
2880 for vi in v:
2881 assert not isinstance(vi, np.ndarray)
2882 else:
2883 assert not isinstance(v, np.ndarray)
2884
2885 def test_zeros_like(self) -> None:
2886 orig = Variable(

Callers

nothing calls this directly

Calls 5

VariableClass · 0.90
full_likeFunction · 0.90
checkFunction · 0.85
chunkMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected