Scalars coordinates have no memory on their DataArray

Abierto
#11,176 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
numpy, python
Área
data

Línea de trabajo

Comienza ejecutando el ejemplo mínimo de xarray y NumPy incluido en el issue y, después, lee la discusión relacionada en el issue #4501. Define cómo debe conservar o exponer un DataArray seleccionado la asociación de coordenadas y añade cobertura de regresión que demuestre el resultado esperado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
4.2k
Forks
1.5k
Merge medio
2 d 21 h
PR fusionados (30 d)
74

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pydata/xarray

Todos los issues de pydata/xarray

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.