MCPcopy
hub / github.com/pydata/xarray / _datetime_nanreduce

Function _datetime_nanreduce

xarray/core/duck_array_ops.py:599–616  ·  view source on GitHub ↗

nanreduce() function for datetime64. Caveats that this function deals with: - In numpy < 1.18, min() on datetime64 incorrectly ignores NaT - numpy nanmin() don't work on datetime64 (all versions at the moment of writing) - dask min() does not work on datetime64 (all versions at the

(array, func)

Source from the content-addressed store, hash-verified

597
598
599def _datetime_nanreduce(array, func):
600 """nanreduce() function for datetime64.
601
602 Caveats that this function deals with:
603
604 - In numpy < 1.18, min() on datetime64 incorrectly ignores NaT
605 - numpy nanmin() don&#x27;t work on datetime64 (all versions at the moment of writing)
606 - dask min() does not work on datetime64 (all versions at the moment of writing)
607 """
608 dtype = array.dtype
609 assert dtypes.is_datetime_like(dtype)
610 # (NaT).astype(float) does not produce NaN...
611 array = where(pandas_isnull(array), np.nan, array.astype(float))
612 array = func(array, skipna=True)
613 if isinstance(array, float):
614 array = np.array(array)
615 # ...but (NaN).astype("M8") does produce NaT
616 return array.astype(dtype)
617
618
619def datetime_to_numeric(array, offset=None, datetime_unit=None, dtype=float):

Callers 3

_datetime_nanminFunction · 0.85
datetime_to_numericFunction · 0.85
meanFunction · 0.85

Calls 3

whereFunction · 0.70
funcFunction · 0.50
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…