7
7
import pandas as pd
8
8
import xarray as xr
9
9
from packaging .version import Version
10
- from xarray .core .duck_array_ops import _datetime_nanmin
11
10
12
11
from .aggregations import Aggregation , Dim , _atleast_1d , quantile_new_dims_func
13
12
from .core import (
18
17
)
19
18
from .core import rechunk_for_blockwise as rechunk_array_for_blockwise
20
19
from .core import rechunk_for_cohorts as rechunk_array_for_cohorts
21
- from .xrutils import _contains_cftime_datetimes , _to_pytimedelta , datetime_to_numeric
22
20
23
21
if TYPE_CHECKING :
24
22
from xarray .core .types import T_DataArray , T_Dataset
@@ -366,22 +364,6 @@ def wrapper(array, *by, func, skipna, core_dims, **kwargs):
366
364
if "nan" not in func and func not in ["all" , "any" , "count" ]:
367
365
func = f"nan{ func } "
368
366
369
- # Flox's count works with non-numeric and its faster than converting.
370
- requires_numeric = func not in ["count" , "any" , "all" ] or (
371
- func == "count" and kwargs ["engine" ] != "flox"
372
- )
373
- if requires_numeric :
374
- is_npdatetime = array .dtype .kind in "Mm"
375
- is_cftime = _contains_cftime_datetimes (array )
376
- if is_npdatetime :
377
- offset = _datetime_nanmin (array )
378
- # xarray always uses np.datetime64[ns] for np.datetime64 data
379
- dtype = "timedelta64[ns]"
380
- array = datetime_to_numeric (array , offset )
381
- elif is_cftime :
382
- offset = array .min ()
383
- array = datetime_to_numeric (array , offset , datetime_unit = "us" )
384
-
385
367
result , * groups = groupby_reduce (array , * by , func = func , ** kwargs )
386
368
387
369
# Transpose the new quantile dimension to the end. This is ugly.
@@ -395,13 +377,6 @@ def wrapper(array, *by, func, skipna, core_dims, **kwargs):
395
377
# output dim order: (*broadcast_dims, *group_dims, quantile_dim)
396
378
result = np .moveaxis (result , 0 , - 1 )
397
379
398
- # Output of count has an int dtype.
399
- if requires_numeric and func != "count" :
400
- if is_npdatetime :
401
- return result .astype (dtype ) + offset
402
- elif is_cftime :
403
- return _to_pytimedelta (result , unit = "us" ) + offset
404
-
405
380
return result
406
381
407
382
# These data variables do not have any of the core dimension,
0 commit comments