Skip to content

Passing xarray_reduce parameter dtype not doing anything #388

@claytharrison

Description

@claytharrison

When I try passing a dtype to xarray_reduce, the output is still uint64 for some reason:

import xarray as xr
from flox.xarray import xarray_reduce

ds = xr.Dataset(
    {
        "counts": ("time", np.array([0,2,1,0,1])),
        "group": ("time", np.array([1,1,1,2,2]))
    },
)
xarray_reduce(ds["counts"],
                ds["group"],
                expected_groups=(np.array([1,2]),),
                func="sum",
                dtype="uint8")
<xarray.DataArray 'counts' (group: 2)> Size: 16B
array([3, 1], dtype=uint64)
Coordinates:
  * group    (group) int64 16B 1 2

This happens whether I use "uint8" as a string or np.uint8.

Of course, I can just use .astype after the fact, but I expect this is an allowed parameter for some reason or another?

Python 3.12.5
flox               0.9.10
xarray             2024.7.0

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