From 31dbc05d86c4018c76562466de0ea569eb1f8a62 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Mon, 18 Jan 2016 19:07:12 -0700 Subject: TST: Add tests for NAT comparison FutureWarning. The behavior of NAT comparisons will change in Numpy 1.13. Make sure that a FutureWarning is emitted when the results will change. --- numpy/core/tests/test_datetime.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'numpy/core') diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py index 8aeaf51ac..601f09c09 100644 --- a/numpy/core/tests/test_datetime.py +++ b/numpy/core/tests/test_datetime.py @@ -1086,6 +1086,34 @@ class TestDateTime(TestCase): assert_equal(np.greater(a, b), [0, 1, 0, 1, 0]) assert_equal(np.greater_equal(a, b), [1, 1, 0, 1, 0]) + def test_datetime_compare_nat(self): + dt_nat = np.datetime64('NaT', 'D') + dt_other = np.datetime64('2000-01-01') + td_nat = np.timedelta64('NaT', 'h') + td_other = np.timedelta64(1, 'h') + + for op in [np.equal, np.less, np.less_equal, + np.greater, np.greater_equal]: + if op(dt_nat, dt_nat): + assert_warns(FutureWarning, op, dt_nat, dt_nat) + if op(dt_nat, dt_other): + assert_warns(FutureWarning, op, dt_nat, dt_other) + if op(dt_other, dt_nat): + assert_warns(FutureWarning, op, dt_other, dt_nat) + if op(td_nat, td_nat): + assert_warns(FutureWarning, op, td_nat, td_nat) + if op(td_nat, td_other): + assert_warns(FutureWarning, op, td_nat, td_other) + if op(td_other, td_nat): + assert_warns(FutureWarning, op, td_other, td_nat) + + assert_warns(FutureWarning, np.not_equal, dt_nat, dt_nat) + assert_(np.not_equal(dt_nat, dt_other)) + assert_(np.not_equal(dt_other, dt_nat)) + assert_warns(FutureWarning, np.not_equal, td_nat, td_nat) + assert_(np.not_equal(td_nat, td_other)) + assert_(np.not_equal(td_other, td_nat)) + def test_datetime_minmax(self): # The metadata of the result should become the GCD # of the operand metadata -- cgit v1.2.1