diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2016-12-26 22:55:40 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2017-05-07 16:21:30 +0200 |
commit | 92aa4080f2a925ff6d03d0b9f80460a53d4c111c (patch) | |
tree | 3c7e8c64474751d8163712193c485b0be823d7a5 /numpy/testing/tests | |
parent | eb8ead6b63df45b148405bb979e0fbd4a32b4125 (diff) | |
download | numpy-92aa4080f2a925ff6d03d0b9f80460a53d4c111c.tar.gz |
BUG: Remove warning filters from comparison assert functions
These warning filters are not threadsafe, while it is nicer if the
comparison functions can be called in a threaded environment since
they do no explicite warning checking.
Less filters are also cleaner in general, though may also mean that
downstream projects see warnings that were previously hidden.
Diffstat (limited to 'numpy/testing/tests')
-rw-r--r-- | numpy/testing/tests/test_utils.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 804f22b7f..e2c105245 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function import warnings import sys import os +import itertools import numpy as np from numpy.testing import ( @@ -144,7 +145,10 @@ class TestArrayEqual(_GenericTest, unittest.TestCase): c['floupipi'] = a['floupi'].copy() c['floupa'] = a['floupa'].copy() - self._test_not_equal(c, b) + with suppress_warnings() as sup: + l = sup.record(FutureWarning, message="elementwise == ") + self._test_not_equal(c, b) + assert_(len(l) == 1) class TestBuildErrorMessage(unittest.TestCase): @@ -208,6 +212,37 @@ class TestEqual(TestArrayEqual): self._assert_func([np.inf], [np.inf]) self._test_not_equal(np.inf, [np.inf]) + def test_nat_items(self): + # not a datetime + nadt_no_unit = np.datetime64("NaT") + nadt_s = np.datetime64("NaT", "s") + nadt_d = np.datetime64("NaT", "ns") + # not a timedelta + natd_no_unit = np.timedelta64("NaT") + natd_s = np.timedelta64("NaT", "s") + natd_d = np.timedelta64("NaT", "ns") + + dts = [nadt_no_unit, nadt_s, nadt_d] + tds = [natd_no_unit, natd_s, natd_d] + for a, b in itertools.product(dts, dts): + self._assert_func(a, b) + self._assert_func([a], [b]) + self._test_not_equal([a], b) + + for a, b in itertools.product(tds, tds): + self._assert_func(a, b) + self._assert_func([a], [b]) + self._test_not_equal([a], b) + + for a, b in itertools.product(tds, dts): + self._test_not_equal(a, b) + self._test_not_equal(a, [b]) + self._test_not_equal([a], [b]) + self._test_not_equal([a], np.datetime64("2017-01-01", "s")) + self._test_not_equal([b], np.datetime64("2017-01-01", "s")) + self._test_not_equal([a], np.timedelta64(123, "s")) + self._test_not_equal([b], np.timedelta64(123, "s")) + def test_non_numeric(self): self._assert_func('ab', 'ab') self._test_not_equal('ab', 'abb') |