Skip to content

Selection with multi-index and float32 values #5700

Closed
@benbovy

Description

@benbovy

I guess it's rather an edge case, but a similar issue than the one fixed in #3153 may occur with multi-indexes:

>>> foo_data = ['a', 'a', 'b', 'b']
>>> bar_data = np.array([0.1, 0.2, 0.7, 0.9], dtype=np.float32)
>>> da = xr.DataArray([1, 2, 3, 4], dims="x", coords={"foo": ("x", foo_data), "bar": ("x", bar_data)})
>>> da = da.set_index(x=["foo", "bar"])
>>> da.sel(bar=0.1)
KeyError: 0.1
>>> da.sel(bar=np.array(0.1, dtype=np.float32).item())
<xarray.DataArray (foo: 1)>
array([1])
Coordinates:
  * foo      (foo) object 'a'

(xarray version: 0.18.2 as there's a regression introduced in 0.19.0 #5691)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions