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

Skip to content

Commit 9340dd4

Browse files
committed
Fix invalid typestring size
Revert to pre numpy 1.7 behavior where invalid typestring size was ignored and isplay deprecate warning. This warning should eventually be changed to an error in future numpy versions.
1 parent 9408b21 commit 9340dd4

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ NPY_NO_EXPORT int
954954
PyArray_TypestrConvert(int itemsize, int gentype)
955955
{
956956
int newtype = NPY_NOTYPE;
957+
PyArray_Descr *temp;
957958

958959
switch (gentype) {
959960
case NPY_GENBOOLLTR:
@@ -1105,7 +1106,28 @@ PyArray_TypestrConvert(int itemsize, int gentype)
11051106
newtype = NPY_TIMEDELTA;
11061107
}
11071108
break;
1109+
default:
1110+
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+
newtype = gentype;
1124+
}
1125+
1126+
Py_DECREF(temp);
1127+
}
1128+
break;
11081129
}
1130+
11091131
return newtype;
11101132
}
11111133

0 commit comments

Comments
 (0)