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