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

Method _setfieldnames

numpy/core/records.py:173–207  ·  view source on GitHub ↗

convert input field names into a list and assign to the _names attribute

(self, names, titles)

Source from the content-addressed store, hash-verified

171 self._nfields = len(keys)
172
173 def _setfieldnames(self, names, titles):
174 """convert input field names into a list and assign to the _names
175 attribute """
176
177 if names:
178 if type(names) in [list, tuple]:
179 pass
180 elif isinstance(names, str):
181 names = names.split(',')
182 else:
183 raise NameError("illegal input names %s" % repr(names))
184
185 self._names = [n.strip() for n in names[:self._nfields]]
186 else:
187 self._names = []
188
189 # if the names are not specified, they will be assigned as
190 # "f0, f1, f2,..."
191 # if not enough names are specified, they will be assigned as "f[n],
192 # f[n+1],..." etc. where n is the number of specified names..."
193 self._names += ['f%d' % i for i in range(len(self._names),
194 self._nfields)]
195 # check for redundant names
196 _dup = find_duplicate(self._names)
197 if _dup:
198 raise ValueError("Duplicate field names: %s" % _dup)
199
200 if titles:
201 self._titles = [n.strip() for n in titles[:self._nfields]]
202 else:
203 self._titles = []
204 titles = []
205
206 if self._nfields > len(titles):
207 self._titles += [None] * (self._nfields - len(titles))
208
209 def _createdtype(self, byteorder):
210 dtype = sb.dtype({

Callers 1

__init__Method · 0.95

Calls 3

find_duplicateFunction · 0.85
stripMethod · 0.80
splitMethod · 0.45

Tested by

no test coverage detected