Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9340dd4 commit d288e39Copy full SHA for d288e39
3 files changed
numpy/core/src/multiarray/conversion_utils.c
@@ -955,6 +955,8 @@ PyArray_TypestrConvert(int itemsize, int gentype)
955
{
956
int newtype = NPY_NOTYPE;
957
PyArray_Descr *temp;
958
+ const char *msg = "Specified size is invalid for this data type.\n"
959
+ "Size will be ignored in NumPy 1.7 but may throw an exception in future versions.";
960
961
switch (gentype) {
962
case NPY_GENBOOLLTR:
@@ -1106,28 +1108,32 @@ PyArray_TypestrConvert(int itemsize, int gentype)
1106
1108
newtype = NPY_TIMEDELTA;
1107
1109
}
1110
break;
- default:
- temp = PyArray_DescrFromType(gentype);
1111
- if (temp != NULL) {
1112
- if (temp->elsize != itemsize) {
1113
-
1114
- const char *msg = "Specified size is invalid for this data type.\n"
1115
- "Size will be ignored in NumPy 1.7 but may throw an exception in future versions.";
1116
- if (DEPRECATE_FUTUREWARNING(msg) < 0) {
1117
- return -1;
1118
- }
1119
1120
- newtype = gentype;
1121
1122
- else {
1123
+ }
+
+ /*
+ * Raise deprecate warning if new type hasn't been
+ * set yet and size char is invalid.
+ * This should eventually be changed to an error in
+ * future NumPy versions.
+ */
+ if (newtype == NPY_NOTYPE) {
+ temp = PyArray_DescrFromType(gentype);
+ if (temp != NULL) {
+ if (temp->elsize != itemsize) {
+ if (DEPRECATE(msg) < 0) {
1124
+ return -1;
1125
1126
- Py_DECREF(temp);
1127
+ newtype = gentype;
1128
- break;
1129
+ else {
1130
1131
1132
1133
+ Py_DECREF(temp);
1134
1135
1136
1137
return newtype;
1138
1139
numpy/core/tests/test_datetime.py
@@ -48,12 +48,11 @@ def test_datetime_dtype_creation(self):
48
assert_raises(TypeError, np.dtype, 'm8[badunit]')
49
assert_raises(TypeError, np.dtype, 'M8[YY]')
50
assert_raises(TypeError, np.dtype, 'm8[YY]')
51
- assert_raises(TypeError, np.dtype, 'M4')
52
- assert_raises(TypeError, np.dtype, 'm4')
53
- assert_raises(TypeError, np.dtype, 'M7')
54
- assert_raises(TypeError, np.dtype, 'm7')
55
- assert_raises(TypeError, np.dtype, 'M16')
56
- assert_raises(TypeError, np.dtype, 'm16')
+ assert_warns(DeprecationWarning, np.dtype, 'm4')
+ assert_warns(DeprecationWarning, np.dtype, 'M7')
+ assert_warns(DeprecationWarning, np.dtype, 'm7')
+ assert_warns(DeprecationWarning, np.dtype, 'M16')
+ assert_warns(DeprecationWarning, np.dtype, 'm16')
57
58
def test_datetime_casting_rules(self):
59
# Cannot cast safely/same_kind between timedelta and datetime
numpy/core/tests/test_dtype.py
@@ -47,13 +47,16 @@ def test_equivalent_dtype_hashing(self):
47
self.assertTrue(hash(left) == hash(right))
def test_invalid_types(self):
- # Make sure invalid type strings raise exceptions
- for typestr in ['O3', 'O5', 'O7', 'b3', 'h4', 'I5', 'l4', 'l8',
- 'L4', 'L8', 'q8', 'q16', 'Q8', 'Q16', 'e3',
- 'f5', 'd8', 't8', 'g12', 'g16',
- 'NA[u4,0xffffffff]']:
+ # Make sure invalid type strings raise exceptions.
+ # For now, display a deprecation warning for invalid
+ # type sizes. In the future this should be changed
+ # to an exception.
+ for typestr in ['O3', 'O5', 'O7', 'b3', 'h4', 'I5', 'l4',
+ 'L4', 'q16', 'Q16', 'e3', 'f5', 'g12']:
#print typestr
- assert_raises(TypeError, np.dtype, typestr)
+ assert_warns(DeprecationWarning, np.dtype, typestr)
+ assert_raises(TypeError, np.dtype, 't8', 'NA[u4,0xffffffff]')
60
61
def test_bad_param(self):
62
# Can't give a size that's too small
0 commit comments