Skip to content

Commit

Permalink
convert datetime: micro-optimizations (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathause authored Sep 7, 2023
1 parent bf49017 commit 5ea713e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flox/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion flox/xrutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5ea713e

Please sign in to comment.