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)
| 597 | |
| 598 | |
| 599 | def _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'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 | |
| 619 | def datetime_to_numeric(array, offset=None, datetime_unit=None, dtype=float): |
no test coverage detected
searching dependent graphs…