Assigning a DataArray with different shape to Dataset variable does not update the variable

オープン
#11,206 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
numpy, python
領域
data

調査の方向性

まず、xarray と numpy を使った最小限の Python 例を実行し、Dataset の変数代入で異なる code 次元がどのように処理されるかを確認します。Dataset の代入に関するテストまたは実装を見つけ、新しい形状と座標の回帰ケースを追加し、代入後に dataSet['open'] が dataArray_new と一致することを確認します。

索引モデルが issue の本文から書いたものです。

説明

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
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.
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
主要言語
Python
スター
4.2k
フォーク
1.5k
平均マージ
2日 21時間
マージ済み PR(30日)
74

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pydata/xarray のほかの issue

pydata/xarray の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。