Closed
Description
What happened?
After vectorized indexing a DataArray with dim x
by a DataArray z
, we get a DataArray with dim z
and x
as non-dim coordinate. But x
is still an IndexVariable, not a normal variable.
What did you expect to happen?
x
should be a normal variable.
Minimal Complete Verifiable Example
import xarray as xr
xr.set_options(display_style="text")
da = xr.DataArray([1, 2, 3], dims="x", coords={"x": [0, 1, 2]})
idxr = xr.DataArray([1], dims="z", name="x", coords={"z": ("z", ["a"])})
da.sel(x=idxr)
<xarray.DataArray (z: 1)>
array([2])
Coordinates:
x (z) int64 1
* z (z) <U1 'a'
x
is a non-dim coordinate but is backed by a IndexVariable with the wrong name!
da.sel(x=idxr).x.variable
<xarray.IndexVariable 'z' (z: 1)>
array([1])
Relevant log output
No response
Anything else we need to know?
No response
Environment
xarray main but this bug was present prior to the explicit indexes refactor.