Skip to content

aggregation functions treat duck arrays differently depending on dtype #3241

Closed
@keewis

Description

@keewis

While working on #3238, I tried replacing np.arange with np.linspace to create test arrays:

>>> ureg = pint.UnitRegistry()
>>> # with int values
>>> array = np.arange(10).astype(int) * ureg.m
>>> np.max(array)
<Quantity(9, 'meter')>
>>> np.max(xr.DataArray(data=array))  # works as expected
<xarray.DataArray ()>
<Quantity(9, 'meter')>
>>> # now with floats
>>> array = np.arange(10).astype(float) * ureg.m
>>> np.max(array)
<Quantity(9.0, 'meter')>
>>> np.max(xr.DataArray(data=array))  # unit information is lost
<xarray.DataArray ()>
array(9.)

Judging by the build logs of #3238, this seems to be the case for all aggregation functions except from np.median and of course those that return booleans or indices.

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