Scalars coordinates have no memory on their DataArray

未关闭
#11,176 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
numpy, python
领域
data

调研方向

首先运行 issue 中的最小 xarray 和 NumPy 示例,然后阅读 issue #4501 中的相关讨论。明确选定的 DataArray 应如何保留或公开坐标关联,并添加展示预期结果的回归测试覆盖。

由索引模型根据 Issue 内容生成。

描述

design question usage question
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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pydata/xarray 的其他 Issue

查看 pydata/xarray 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。