Skip to content

Commit

Permalink
In xarray too
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Oct 7, 2023
1 parent d4e30d8 commit c8000e3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flox/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .aggregations import Aggregation, _atleast_1d
from .core import (
_choose_engine,
_convert_expected_groups_to_index,
_get_expected_groups,
_validate_expected_groups,
Expand Down Expand Up @@ -72,7 +73,7 @@ def xarray_reduce(
fill_value=None,
dtype: np.typing.DTypeLike = None,
method: str = "map-reduce",
engine: str = None,
engine: str | None = None,
keep_attrs: bool | None = True,
skipna: bool | None = None,
min_count: int | None = None,
Expand Down Expand Up @@ -362,9 +363,12 @@ def wrapper(array, *by, func, skipna, core_dims, **kwargs):
if "nan" not in func and func not in ["all", "any", "count"]:
func = f"nan{func}"

if kwargs.get("engine", None) is None:
kwargs["engine"] = _choose_engine(by, func)

# Flox's count works with non-numeric and its faster than converting.
requires_numeric = func not in ["count", "any", "all"] or (
func == "count" and engine != "flox"
func == "count" and kwargs["engine"] != "flox"
)
if requires_numeric:
is_npdatetime = array.dtype.kind in "Mm"
Expand Down

0 comments on commit c8000e3

Please sign in to comment.