From df54ff86105288ca2fabdf410c3b415399276e2c Mon Sep 17 00:00:00 2001 From: Tyler Reddy Date: Wed, 9 Jan 2019 11:46:15 -0800 Subject: BUG: timedelta64 % 0 behavior * modulus operation with two timedelta64 operands now returns NaT in the case of division by zero, rather than returning zero --- numpy/core/src/umath/loops.c.src | 2 +- numpy/core/tests/test_datetime.py | 2 +- 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 -- cgit v1.2.1