summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Reddy <tyler.je.reddy@gmail.com>2019-01-09 11:46:15 -0800
committerTyler Reddy <tyler.je.reddy@gmail.com>2019-01-17 18:46:32 -0800
commitdf54ff86105288ca2fabdf410c3b415399276e2c (patch)
treee1ba9f80efe1a130aa8d8eb503680333d862d8ce
parent4e724834fae348af564e38e6528ce2dab131e61a (diff)
downloadnumpy-df54ff86105288ca2fabdf410c3b415399276e2c.tar.gz
BUG: timedelta64 % 0 behavior
* modulus operation with two timedelta64 operands now returns NaT in the case of division by zero, rather than returning zero
-rw-r--r--numpy/core/src/umath/loops.c.src2
-rw-r--r--numpy/core/tests/test_datetime.py2
2 files changed, 2 insertions, 2 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index 6accf3065..9e204eab5 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -1623,7 +1623,7 @@ TIMEDELTA_mm_m_remainder(char **args, npy_intp *dimensions, npy_intp *steps, voi
else {
if (in2 == 0) {
npy_set_floatstatus_divbyzero();
- *((npy_timedelta *)op1) = 0;
+ *((npy_timedelta *)op1) = NPY_DATETIME_NAT;
}
else {
/* handle mixed case the way Python does */
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index cb7555a34..4ee8a3065 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -1758,7 +1758,7 @@ class TestDateTime(object):
def test_timedelta_modulus_div_by_zero(self):
with assert_warns(RuntimeWarning):
actual = np.timedelta64(10, 's') % np.timedelta64(0, 's')
- assert_equal(actual, np.timedelta64(0, 's'))
+ assert_equal(actual, np.timedelta64('NaT'))
@pytest.mark.parametrize("val1, val2", [
# cases where one operand is not