You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importnumpyasnpimportxarrayasxrda=xr.DataArray(
np.random.random((3, 4)),
dims=["assets", "year"],
coords={"year": range(2010, 2018, 2)}
)
# Interpolate directly the DataArraynew_da=da.interp(year=[2011, 2015])
new_da.loc[{"year": 2015}] =42# WORKS!print(new_da)
# Interpolate DataArray as part of a Datasetdset=xr.Dataset({"my_array": da.copy()}).interp(year=[2011, 2015])
new_da=dset.my_arraynew_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.
Code Sample, a copy-pastable example if possible
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.
Output of
xr.show_versions()
The text was updated successfully, but these errors were encountered: