Scalars coordinates have no memory on their DataArray
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先运行 issue 中的最小 xarray 和 NumPy 示例,然后阅读 issue #4501 中的相关讨论。明确选定的 DataArray 应如何保留或公开坐标关联,并添加展示预期结果的回归测试覆盖。
由索引模型根据 Issue 内容生成。
描述
What happened?
I am noticing an issue which might be a bug or a feature, but leaves me quite puzzled. I understand that scalar coordinates are transported all together when slicing/selection is operated to make smooth operations across datasets.
However, when I have a dataset with two variables depending on two different coordinates but sharing a third one, if I operate selection on both the first two coordinates and then select one of the two variable available, I obtain a DataArray where both my coordinates are scalar and there is no way - apparently - to know which coordinate is associated to my DataArray. I tried to provide an example below, and the output looks agnostic to my coordinates y and z. In the example below var1 and var2 have the same dimensions x and the same (scalar) coordinates y and z. Both DataArray could lie on both of coordinate and I have no way to know it without knowing its history.
Thanks for any hint!
What did you expect to happen?
To have an attribute, index or anything else into the final DataArray that helps me to guess what is the coordinate on which my variable depends on. In the example below var1 and var2 have the same dimensions x and the same (scalar) coordinates y and z.
Minimal Complete Verifiable Example
import xarray as xr
import numpy as np
arr = xr.Dataset(
{'var1': (('y', 'x'), np.zeros((1,5))),
'var2': (('z', 'x'), np.zeros((1,5)))},
coords={'y': ('y', [10]), 'z': ('z', [20])})
arr.isel(y=0, z=0)['var1']
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
Anything else we need to know?
I checked other issues, the only one that seems relevant is https://github.com/pydata/xarray/issues/4501 but I am not sure I fully understand the implications
Environment
INSTALLED VERSIONS
commit: None
python: 3.14.2 | packaged by conda-forge | (main, Jan 26 2026, 20:19:28) [Clang 20.1.8 ]
python-bits: 64
OS: Darwin
OS-release: 23.6.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: None
LOCALE: (None, 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3
xarray: 2025.9.0
pandas: 3.0.0
numpy: 2.3.5
scipy: None
netCDF4: 1.7.4
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.5
nc_time_axis: None
iris: None
bottleneck: None
dask: 2026.1.1
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: 2026.1.0
cupy: None
pint: None
sparse: 0.17.0
flox: None
numpy_groupies: None
setuptools: 80.10.2
pip: 25.3
conda: None
pytest: 9.0.2
mypy: None
IPython: 9.9.0
sphinx: None
- 主要语言
- Python
- 星标
- 4.2k
- 派生
- 1.5k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 74
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pydata/xarray 的其他 Issue
-
xarray removes axis grid from pcolormesh可能已有人在做 @Sealdot 今天认领。 未关闭bug needs triage
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
`DataTree.map_over_datasets` behavior can be obscure sometimes可能已有人在做 @mohansree14 于 24 天前认领。 未关闭needs triage
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
Comparing attrs that contain a dict of NumPy arrays raises ValueError in identical / assert_identical可能已有人在做 @SohamXYZDev 于 29 天前认领。 未关闭bug needs triage
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
RangeIndex` with datetime64 bounds cannot be printed (`Unknown format code 'g'`)可能已有人在做 @d-chambers 于 60 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
DataTree constructor error message says dict even though dict is not accepted可能已有人在做 @aryansk 于 100 天前认领。 未关闭bug contrib-good-first-issue topic-DataTree topic-error reporting
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
abetlen/llama-cpp-python#2424 ·
维护者通常 1 天内回复
-
Bug IronPython Python 3
难度 2/5 1-3 小时 新手友好度 72/100
pyrevitlabs/pyRevit#4184 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复