diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-08-31 20:21:32 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-08-31 20:21:32 -0600 |
commit | d4413a319ed90a99621bc105bc35a820f65dbf5d (patch) | |
tree | 63da47ce49a71c9f419d6a9ebcdaf8e4d14fdc6d | |
parent | 03371cdae281bbbde0c7adfc28d012d6555ad112 (diff) | |
download | numpy-d4413a319ed90a99621bc105bc35a820f65dbf5d.tar.gz |
BUG: Catch DeprecationWarning in numpy/core/tests/test_numeric.py.
TestCreationFuncs.check_function was spewing Deprecation warnings in
release mode. AFAICT, it did not raise errors during development because
it was buried by a TypeError. The Deprecation in question is at line
1141 in multiarray/conversion_utils.c. Hiding the deprecation should
be harmless here, but when the Deprecation is turned into an error
it will need to be caught in the test.
-rw-r--r-- | numpy/core/tests/test_numeric.py | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 6202bd125..629cb6090 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -4,6 +4,7 @@ import sys import platform from decimal import Decimal import warnings +import itertools import numpy as np from numpy.core import * @@ -1493,8 +1494,7 @@ class TestStdVarComplex(TestCase): class TestCreationFuncs(TestCase): - - '''Test ones, zeros, empty and filled''' + #Test ones, zeros, empty and filled def setUp(self): self.dtypes = ('b', 'i', 'u', 'f', 'c', 'S', 'a', 'U', 'V') @@ -1502,36 +1502,41 @@ class TestCreationFuncs(TestCase): self.ndims = 10 def check_function(self, func, fill_value=None): + par = ( + (0, 1, 2), + range(self.ndims), + self.orders, + self.dtypes, + 2**np.arange(9) + ) fill_kwarg = {} if fill_value is not None: fill_kwarg = {'fill_value': fill_value} - for size in (0, 1, 2): # size in one dimension - for ndims in range(self.ndims): # [], [size], [size, size] etc. + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + for size, ndims, order, type, bytes in itertools.product(*par): shape = ndims * [size] - for order in self.orders: # C, F - for type in self.dtypes: # bool, int, float etc. - for bytes in 2**np.arange(9): # byte size for type - try: - dtype = np.dtype('{0}{1}'.format(type, bytes)) - except TypeError: # dtype combination does not exist - continue - else: - # do not fill void type - if fill_value is not None and type in 'V': - continue - - arr = func(shape, order=order, dtype=dtype, - **fill_kwarg) - - assert arr.dtype == dtype - assert getattr(arr.flags, self.orders[order]) - - if fill_value is not None: - if dtype.str.startswith('|S'): - val = str(fill_value) - else: - val = fill_value - assert_equal(arr, dtype.type(val)) + try: + dtype = np.dtype('{0}{1}'.format(type, bytes)) + except TypeError: # dtype combination does not exist + continue + else: + # do not fill void type + if fill_value is not None and type in 'V': + continue + + arr = func(shape, order=order, dtype=dtype, + **fill_kwarg) + + assert_(arr.dtype == dtype) + assert_(getattr(arr.flags, self.orders[order])) + + if fill_value is not None: + if dtype.str.startswith('|S'): + val = str(fill_value) + else: + val = fill_value + assert_equal(arr, dtype.type(val)) def test_zeros(self): self.check_function(np.zeros) |