Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6209e3e

Browse files
committed
Refactor unit tests and add DECREF
- Refactor unit tests for invalid dtypes so that each test is on a separate line. This will make it easier to figure out which typestring is failing the unit test. - Add Py_DECREF for temp variable
1 parent ab2d5d2 commit 6209e3e

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,7 @@ PyArray_TypestrConvert(int itemsize, int gentype)
11211121
if (temp != NULL) {
11221122
if (temp->elsize != itemsize) {
11231123
if (DEPRECATE(msg) < 0) {
1124+
Py_DECREF(temp);
11241125
return -1;
11251126
}
11261127

numpy/core/tests/test_dtype.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,20 @@ def test_equivalent_dtype_hashing(self):
4747
self.assertTrue(hash(left) == hash(right))
4848

4949
def test_invalid_types(self):
50-
# Make sure invalid type strings raise exceptions.
50+
# Make sure invalid type strings raise a warning.
5151
# For now, display a deprecation warning for invalid
5252
# type sizes. In the future this should be changed
5353
# to an exception.
5454

55-
for typestr in ['O3', 'O5', 'O7', 'b3', 'h4', 'I5',
56-
'e3', 'f5', 'g12']:
57-
#print typestr
58-
assert_warns(DeprecationWarning, np.dtype, typestr)
55+
assert_warns(DeprecationWarning, np.dtype, 'O3')
56+
assert_warns(DeprecationWarning, np.dtype, 'O5')
57+
assert_warns(DeprecationWarning, np.dtype, 'O7')
58+
assert_warns(DeprecationWarning, np.dtype, 'b3')
59+
assert_warns(DeprecationWarning, np.dtype, 'h4')
60+
assert_warns(DeprecationWarning, np.dtype, 'I5')
61+
assert_warns(DeprecationWarning, np.dtype, 'e3')
62+
assert_warns(DeprecationWarning, np.dtype, 'f5')
63+
assert_warns(DeprecationWarning, np.dtype, 'g12')
5964

6065
if np.dtype('l').itemsize == 8:
6166
assert_warns(DeprecationWarning, np.dtype, 'l4')
@@ -71,8 +76,6 @@ def test_invalid_types(self):
7176
assert_warns(DeprecationWarning, np.dtype, 'q8')
7277
assert_warns(DeprecationWarning, np.dtype, 'Q8')
7378

74-
assert_raises(TypeError, np.dtype, 't8', 'NA[u4,0xffffffff]')
75-
7679
def test_bad_param(self):
7780
# Can't give a size that's too small
7881
assert_raises(ValueError, np.dtype,

0 commit comments

Comments
 (0)