Skip to content

Indexing with quantified coordinates #276

@SGeeversAtVortech

Description

@SGeeversAtVortech

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions