Open
Description
What is your issue?
Consider the following example:
In [1]: import xarray
In [2]: ds = xarray.Dataset(coords={'x': [1, 2, 3]})
In [3]: ds['y'] = ds['x']
In [4]: ds
Out[4]:
<xarray.Dataset> Size: 48B
Dimensions: (x: 3)
Coordinates:
* x (x) int64 24B 1 2 3
Data variables:
y (x) int64 24B 1 2 3
In [5]: ds['y'].variable
Out[5]:
<xarray.IndexVariable 'x' (x: 3)> Size: 24B
array([1, 2, 3])
In [6]: ds['x'].variable is ds['y'].variable
Out[6]: False
The assigned variable 'y'
still uses an IndexVariable under the hood, which means it has immutable data. This is not very useful.
Instead, assigning a DataArray that contains a wrapped IndexVariable to a Dataset should create a new varaible of the base Variable type.