-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Code Sample, a copy-pastable example if possible
import numpy as np
import xarray as xr
da = xr.DataArray(
np.random.random((3, 4)),
dims=["assets", "year"],
coords={"year": range(2010, 2018, 2)}
)
# Interpolate directly the DataArray
new_da = da.interp(year=[2011, 2015])
new_da.loc[{"year": 2015}] = 42 # WORKS!
print(new_da)
# Interpolate DataArray as part of a Dataset
dset = xr.Dataset({"my_array": da.copy()}).interp(year=[2011, 2015])
new_da = dset.my_array
new_da.loc[{"year": 2015}] = 42 # DOESN'T WORK!
print(new_da)Problem description
Assigning a value to some locations of a DataArray after it has been interpolated raises an IndexError. This does not occur when the DataArray is interpolated independently, only occurs when the DataArray has been interpolated as part of a Dataset.
This problem is not present in xarray<0.12.0
Expected Output
The above example should print new_da in both cases, with the values corresponding to year 2015 replaced by 42. That works in the first case, but fails in the second raising IndexError.
Although I am not sure if it is the cause of this error, I have found that in the first case the array indexes are present and contain [2011, 2015], but they are an empty OrderDict in the second case.