Thanks to visit codestin.com
Credit goes to github.com

Skip to content

np.isnan raises an error for datetime (NaT)  #14831

Closed
@mathause

Description

@mathause

Reproducing code example:

import numpy as np
a = np.array(['1999-12-15', 'NaT'], dtype='M8[ns]')

np.isnan(a)
np.nanmin(a)
np.nanmax(a)

Error message:

Each of those raises an:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Background

Numpy 1.18 returns NaT for np.min(a) (it did skip NaT before 1.18; #14717). This breaks xarray (pydata/xarray#3409) and pandas (pandas-dev/pandas#29058) - therefore it would be good to make np.isnan work with datetime.

Also: #9009, #1307, #5222

Numpy/Python version information:

1.18.0.dev0+3b5db53 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
[GCC 7.3.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions