8000 BUG: Catch DeprecationWarning in numpy/core/tests/test_numeric.py. · juliantaylor/numpy@d4413a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4413a3

Browse files
committed
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.
1 parent 03371cd commit d4413a3

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

numpy/core/tests/test_numeric.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import platform
55
from decimal import Decimal
66
import warnings
7+
import itertools
78

89
import numpy as np
910
from numpy.core import *
@@ -1493,45 +1494,49 @@ def test_basic(self):
14931494

14941495

14951496
class TestCreationFuncs(TestCase):
1496-
1497-
'''Test ones, zeros, empty and filled'''
1497+
#Test ones, zeros, empty and filled
14981498

14991499
def setUp(self):
15001500
self.dtypes = ('b', 'i', 'u', 'f', 'c', 'S', 'a', 'U', 'V')
15011501
self.orders = {'C': 'c_contiguous', 'F': 'f_contiguous'}
15021502
self.ndims = 10
15031503

15041504
def check_function(self, func, fill_value=None):
1505+
par = (
1506+
(0, 1, 2),
1507+
range(self.ndims),
1508+
self.orders,
1509+
self.dtypes,
1510+
2**np.arange(9)
1511+
)
15051512
fill_kwarg = {}
15061513
if fill_value is not None:
15071514
fill_kwarg = {'fill_value': fill_value}
1508-
for size in (0, 1, 2): # size in one dimension
1509-
for ndims in range(self.ndims): # [], [size], [size, size] etc.
1515+
with warnings.catch_warnings():
1516+
warnings.simplefilter('ignore', DeprecationWarning)
1517+
for size, ndims, order, type, bytes in itertools.product(*par):
15101518
shape = ndims * [size]
1511-
for order in self.orders: # C, F
1512-
for type in self.dtypes: # bool, int, float etc.
1513-
for bytes in 2**np.arange(9): # byte size for type
1514-
try:
1515-
dtype = np.dtype('{0}{1}'.format(type, bytes))
1516-
except TypeError: # dtype combination does not exist
1517-
continue
1518-
else:
1519-
# do not fill void type
1520-
if fill_value is not None and type in 'V':
1521-
continue
1522-
1523-
arr = func(shape, order=order, dtype=dtype,
1524-
**fill_kwarg)
1525-
1526-
assert arr.dtype == dtype
1527-
assert getattr(arr.flags, self.orders[order])
1528-
1529-
if fill_value is not None:
1530-
if dtype.str.startswith('|S'):
1531-
val = str(fill_value)
1532-
else:
1533-
val = fill_value
1534-
assert_equal(arr, dtype.type(val))
1519+
try:
1520+
dtype = np.dtype('{0}{1}'.format(type, bytes))
1521+
except TypeError: # dtype combination does not exist
1522+
continue
1523+
else:
1524+
# do not fill void type
1525+
if fill_value is not None and type in 'V':
1526+
continue
1527+
1528+
arr = func(shape, order=order, dtype=dtype,
1529+
**fill_kwarg)
1530+
1531+
assert_(arr.dtype == dtype)
1532+
assert_(getattr(arr.flags, self.orders[order]))
1533+
1534+
if fill_value is not None:
1535+
if dtype.str.startswith('|S'):
1536+
val = str(fill_value)
1537+
else:
1538+
val = fill_value
1539+
assert_equal(arr, dtype.type(val))
15351540

15361541
def test_zeros(self):
15371542
self.check_function(np.zeros)

0 commit comments

Comments
 (0)
0