MCPcopy Create free account
hub / github.com/numpy/numpy / _commastring

Function _commastring

numpy/core/_internal.py:157–203  ·  view source on GitHub ↗
(astr)

Source from the content-addressed store, hash-verified

155_convorder = {'=': _nbo}
156
157def _commastring(astr):
158 startindex = 0
159 result = []
160 while startindex < len(astr):
161 mo = format_re.match(astr, pos=startindex)
162 try:
163 (order1, repeats, order2, dtype) = mo.groups()
164 except (TypeError, AttributeError):
165 raise ValueError(
166 f'format number {len(result)+1} of "{astr}" is not recognized'
167 ) from None
168 startindex = mo.end()
169 # Separator or ending padding
170 if startindex < len(astr):
171 if space_re.match(astr, pos=startindex):
172 startindex = len(astr)
173 else:
174 mo = sep_re.match(astr, pos=startindex)
175 if not mo:
176 raise ValueError(
177 'format number %d of "%s" is not recognized' %
178 (len(result)+1, astr))
179 startindex = mo.end()
180
181 if order2 == '':
182 order = order1
183 elif order1 == '':
184 order = order2
185 else:
186 order1 = _convorder.get(order1, order1)
187 order2 = _convorder.get(order2, order2)
188 if (order1 != order2):
189 raise ValueError(
190 'inconsistent byte-order specification %s and %s' %
191 (order1, order2))
192 order = order1
193
194 if order in ('|', '=', _nbo):
195 order = ''
196 dtype = order + dtype
197 if (repeats == ''):
198 newitem = dtype
199 else:
200 newitem = (dtype, ast.literal_eval(repeats))
201 result.append(newitem)
202
203 return result
204
205class dummy_ctype:
206 def __init__(self, cls):

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected