Closed bertcoerver closed 4 days ago
Yes the issue is here: https://github.com/pydata/xarray/blob/a04d857a03d1fb04317d636a7f23239cb9034491/xarray/core/groupby.py#L751-L752
Setting np.nan
will promote the output to default float type for your platform. That's why setting dtype
alone doesn't work.
Using flox directly preserves the dtype without any extra work:
import flox.xarray
flox.xarray.xarray_reduce(ds, "idx", func="max")
so perhaps use that for now.
What happened?
I'm applying a reduction on some data, but the
dtype
keyword documented here doesn't seem to work, without also specifying afill_value
.Not sure if it's a bug, but otherwise it would be nice to make a note of this in the documentation.
What did you expect to happen?
I expect the output to have the
dtype
specified by thedtype
keyword.Minimal Complete Verifiable Example
Given a dataset with
int16
data:The following casts the
"test"
variable tofloat64
(as expected):However, doing this:
Also gives
float64
as output dtype.Only once I also specify a
fill_value
, the output follows the specified dtype, e.g.:gives
x["test"].dtype.name == "int16"
, or:gives
x["test"].dtype.name == "int32"
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment