pint-xarray icon indicating copy to clipboard operation
pint-xarray copied to clipboard

Indexing with quantified coordinates

Open SGeeversAtVortech opened this issue 1 year ago • 1 comments

It seems not possible to index an array with quantified coordinates; see the example below.

import pint
import pint_xarray
import xarray as xr

unit_registry = pint.UnitRegistry(force_ndarray_like=True)
Q_ = unit_registry.Quantity

y = xr.DataArray(name="y", data=[1, 2], coords={"x": [1, 2]})
yq = y.pint.quantify({"y": "km", "x": "s"})
yq.loc[Q_(1, "s")]  # UnitStrippedWarning
yq.loc[Q_(1000, "ms")]  # KeyError

The line yq.loc[Q_(1, "s")] will raise a UnitStrippedWarning and the line yq.loc[Q_(1000, "ms")] will give the same warning and then raise a KeyError.

Should one just avoid using quantified coordinates? Or are there plans to enable indexing with quantities?

SGeeversAtVortech avatar Oct 03 '24 14:10 SGeeversAtVortech