Elffuss BraidHub

kikocis/auto-code-rover public

main · 2.3 KiBRawPermalink
1DataSet.update causes chunked dask DataArray to evalute its values eagerly
2**What happened**:
3Used `DataSet.update` to update a chunked dask DataArray, but the DataArray is no longer chunked after the update.
4
5**What you expected to happen**:
6The chunked DataArray should still be chunked after the update
7
8**Minimal Complete Verifiable Example**:
9
10```python
11foo = xr.DataArray(np.random.randn(3, 3), dims=("x", "y")).chunk() # foo is chunked
12ds = xr.Dataset({"foo": foo, "bar": ("x", [1, 2, 3])}) # foo is still chunked here
13ds # you can verify that foo is chunked
14```
15```python
16update_dict = {"foo": (("x", "y"), ds.foo[1:, :]), "bar": ("x", ds.bar[1:])}
17update_dict["foo"][1] # foo is still chunked
18```
19```python
20ds.update(update_dict)
21ds # now foo is no longer chunked
22```
23
24**Environment**:
25
26<details><summary>Output of <tt>xr.show_versions()</tt></summary>
27
28```
29commit: None
30python: 3.8.3 (default, Jul 2 2020, 11:26:31)
31[Clang 10.0.0 ]
32python-bits: 64
33OS: Darwin
34OS-release: 19.6.0
35machine: x86_64
36processor: i386
37byteorder: little
38LC_ALL: None
39LANG: en_US.UTF-8
40LOCALE: en_US.UTF-8
41libhdf5: 1.10.6
42libnetcdf: None
43
44xarray: 0.16.0
45pandas: 1.0.5
46numpy: 1.18.5
47scipy: 1.5.0
48netCDF4: None
49pydap: None
50h5netcdf: None
51h5py: 2.10.0
52Nio: None
53zarr: None
54cftime: None
55nc_time_axis: None
56PseudoNetCDF: None
57rasterio: None
58cfgrib: None
59iris: None
60bottleneck: None
61dask: 2.20.0
62distributed: 2.20.0
63matplotlib: 3.2.2
64cartopy: None
65seaborn: None
66numbagg: None
67pint: None
68setuptools: 49.2.0.post20200714
69pip: 20.1.1
70conda: None
71pytest: 5.4.3
72IPython: 7.16.1
73sphinx: None
74```
75
76</details>
77Dataset constructor with DataArray triggers computation
78Is it intentional that creating a Dataset with a DataArray and dimension names for a single variable causes computation of that variable? In other words, why does ```xr.Dataset(dict(a=('d0', xr.DataArray(da.random.random(10)))))``` cause the dask array to compute?
79
80A longer example:
81
82```python
83import dask.array as da
84import xarray as xr
85x = da.random.randint(1, 10, size=(100, 25))
86ds = xr.Dataset(dict(a=xr.DataArray(x, dims=('x', 'y'))))
87type(ds.a.data)
88dask.array.core.Array
89
90# Recreate the dataset with the same array, but also redefine the dimensions
91ds2 = xr.Dataset(dict(a=(('x', 'y'), ds.a))
92type(ds2.a.data)
93numpy.ndarray
94```
95
96