From 5ea713efb5019ff9627893060a6c707a1d14170a Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Thu, 7 Sep 2023 11:04:10 +0200 Subject: [PATCH] convert datetime: micro-optimizations (#261) --- flox/xarray.py | 4 ++-- flox/xrutils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flox/xarray.py b/flox/xarray.py index acd3f2d6c..487850ca0 100644 --- a/flox/xarray.py +++ b/flox/xarray.py @@ -374,8 +374,8 @@ def wrapper(array, *by, func, skipna, core_dims, **kwargs): # xarray always uses np.datetime64[ns] for np.datetime64 data dtype = "timedelta64[ns]" array = datetime_to_numeric(array, offset) - elif _contains_cftime_datetimes(array): - offset = min(array) + elif is_cftime: + offset = array.min() array = datetime_to_numeric(array, offset, datetime_unit="us") result, *groups = groupby_reduce(array, *by, func=func, **kwargs) diff --git a/flox/xrutils.py b/flox/xrutils.py index 45cf45eec..958bd3976 100644 --- a/flox/xrutils.py +++ b/flox/xrutils.py @@ -157,7 +157,7 @@ def datetime_to_numeric(array, offset=None, datetime_unit=None, dtype=float): if array.dtype.kind in "Mm": offset = _datetime_nanmin(array) else: - offset = min(array) + offset = array.min() # Compute timedelta object. # For np.datetime64, this can silently yield garbage due to overflow.