What happened?
I encountered an issue when trying to assign a new DataArray to an existing variable in an xarray Dataset. The assignment appears to not update the variable as expected.
Here is a minimal example that reproduces the problem:
What did you expect to happen?
After the assignment, dataSet['open']should have the same data and coordinates as dataArray_new, i.e., shape (3,3) with codes ['000123', '000456', '000111'].
Minimal Complete Verifiable Example
import xarray as xr
import numpy as np
DataTime=[20260102,20260103,20260104]
codes = ['000123', '000456']
dataArray = xr.DataArray(
np.random.randn(len(DataTime), len(codes)),
dims=['time', 'code'],
coords={'code': codes,'time': DataTime}
)
dataArray_new = xr.DataArray(
np.random.randn(len(DataTime), 3),
dims=['time', 'code'],
coords={'code': ['000123', '000456','000111'],'time': DataTime}
)
dataSet = xr.Dataset({'open': dataArray})
dataSet['open']=dataArray_new
print(dataSet['open'])
print()
print(dataArray_new)
print("xarray version",xr.__version__)
Steps to reproduce
No response
MVCE confirmation
Relevant log output
output:
Python 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)] on win32
Enter "help" below or click "Help" above for more information.
= RESTART: C:/Users/Administrator/AppData/Local/Programs/Python/Python313/delok.py
<xarray.DataArray 'open' (time: 3, code: 2)> Size: 48B
array([[ 0.00311068, -1.68021968],
[ 0.23174369, 1.72308605],
[ 0.05651745, -0.07747445]])
Coordinates:
time (time) int64 24B 20260102 20260103 20260104
code (code) <U6 48B '000123' '000456'
<xarray.DataArray (time: 3, code: 3)> Size: 72B
array([[ 0.00311068, -1.68021968, -1.19742281],
[ 0.23174369, 1.72308605, -1.11061083],
[ 0.05651745, -0.07747445, 0.70037003]])
Coordinates:
time (time) int64 24B 20260102 20260103 20260104
code (code) <U6 72B '000123' '000456' '000111'
xarray version 2026.1.0
Anything else we need to know?
No response
Environment
Details
What happened?
I encountered an issue when trying to assign a new DataArray to an existing variable in an xarray Dataset. The assignment appears to not update the variable as expected.
Here is a minimal example that reproduces the problem:
What did you expect to happen?
After the assignment, dataSet['open']should have the same data and coordinates as dataArray_new, i.e., shape (3,3) with codes ['000123', '000456', '000111'].
Minimal Complete Verifiable Example
Steps to reproduce
No response
MVCE confirmation
Relevant log output
Anything else we need to know?
No response
Environment
Details