diff options
-rw-r--r-- | doc/release/1.14.0-notes.rst | 6 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_type_resolution.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_datetime.py | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/doc/release/1.14.0-notes.rst b/doc/release/1.14.0-notes.rst index a4b61e038..03ae8ed91 100644 --- a/doc/release/1.14.0-notes.rst +++ b/doc/release/1.14.0-notes.rst @@ -140,6 +140,12 @@ The previous parameter name ``from`` is a reserved keyword in Python, which made it difficult to pass the argument by name. This has been fixed by renaming the parameter to ``from_``. +``isnat`` raises ``TypeError`` when passed wrong type +------------------------------------------------------ +The ufunc ``isnat`` used to raise a ``ValueError`` when it was not passed +variables of type ``datetime`` or ``timedelta``. This has been changed to +raising a ``TypeError``. + C API changes ============= diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c index e77b48fc4..1766ba564 100644 --- a/numpy/core/src/umath/ufunc_type_resolution.c +++ b/numpy/core/src/umath/ufunc_type_resolution.c @@ -544,7 +544,7 @@ PyUFunc_IsNaTTypeResolver(PyUFuncObject *ufunc, PyArray_Descr **out_dtypes) { if (!PyTypeNum_ISDATETIME(PyArray_DESCR(operands[0])->type_num)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_TypeError, "ufunc 'isnat' is only defined for datetime and timedelta."); return -1; } diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py index 10fa9b060..dc84a039c 100644 --- a/numpy/core/tests/test_datetime.py +++ b/numpy/core/tests/test_datetime.py @@ -1963,7 +1963,7 @@ class TestDateTime(object): for t in np.typecodes["All"]: if t in np.typecodes["Datetime"]: continue - assert_raises(ValueError, np.isnat, np.zeros(10, t)) + assert_raises(TypeError, np.isnat, np.zeros(10, t)) class TestDateTimeData(object): |