@@ -102,28 +102,29 @@ cdef str _make_typestr(int typenum):
102
102
return type_to_str[typenum] + str (type_bytesize(typenum))
103
103
104
104
105
- cdef int typenum_from_format(str s) except * :
105
+ cdef int typenum_from_format(str s):
106
106
"""
107
107
Internal utility to convert string describing type format
108
108
109
109
Format is [<|=>][biufc]#
110
110
Shortcuts for formats are i, u, d, D
111
111
"""
112
112
if not s:
113
- raise TypeError ( " Format string ' " + s + " ' cannot be empty. " )
113
+ return - 1
114
114
try :
115
115
dt = np.dtype(s)
116
- except Exception as e :
117
- raise TypeError ( " Format ' " + s + " ' is not understood. " ) from e
116
+ except Exception :
117
+ return - 1
118
118
if (dt.byteorder == " >" ):
119
- raise TypeError ( " Format ' " + s + " ' can only have native byteorder. " )
119
+ return - 2
120
120
return dt.num
121
121
122
+
122
123
cdef int descr_to_typenum(object dtype):
123
124
" Returns typenum for argumentd dtype that has attribute descr, assumed numpy.dtype"
124
125
obj = getattr (dtype, ' descr' )
125
126
if (not isinstance (obj, list ) or len (obj) != 1 ):
126
- return - 1
127
+ return - 1 # token for ValueError
127
128
obj = obj[0 ]
128
129
if (not isinstance (obj, tuple ) or len (obj) != 2 or obj[0 ]):
129
130
return - 1
@@ -143,9 +144,11 @@ cdef int dtype_to_typenum(dtype) except *:
143
144
else :
144
145
try :
145
146
dt = np.dtype(dtype)
146
- if hasattr (dt, ' descr' ):
147
- return descr_to_typenum(dt)
148
- else :
149
- return - 1
147
+ except TypeError :
148
+ return - 3
150
149
except Exception :
151
150
return - 1
151
+ if hasattr (dt, ' descr' ):
152
+ return descr_to_typenum(dt)
153
+ else :
154
+ return - 3 # token for TypeError
0 commit comments