summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeno Goertz <keno@goertz-berlin.com>2017-10-08 00:55:28 +0200
committerKeno Goertz <keno@goertz-berlin.com>2017-10-11 09:23:06 +0200
commit3ed10bdd42d2c8393c89114a0cd60a807ddd51b3 (patch)
treedc907f410dab8a4b99760e026375ba4283933296
parentacae8a4351885c777671be8dfd3cd7a7034b0731 (diff)
downloadnumpy-3ed10bdd42d2c8393c89114a0cd60a807ddd51b3.tar.gz
BUG: Raise TypeError instead of ValueError for ufunc isnat if operand is not of type datetime or timedelta
TST: Edited test_datetime to expect a TypeError instead of a ValueError for isnat if a wrong type is passed as an argument DOC: Added change of ufunc isnat's exception handling to release notes
-rw-r--r--doc/release/1.14.0-notes.rst6
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.c2
-rw-r--r--numpy/core/tests/test_datetime.py2
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):