MCPcopy Index your code
hub / github.com/numpy/numpy / _setfieldnames

Method _setfieldnames

numpy/_core/records.py:146–180  ·  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

144 self._nfields = len(keys)
145
146 def _setfieldnames(self, names, titles):
147 """convert input field names into a list and assign to the _names
148 attribute """
149
150 if names:
151 if type(names) in [list, tuple]:
152 pass
153 elif isinstance(names, str):
154 names = names.split(',')
155 else:
156 raise NameError(f"illegal input names {repr(names)}")
157
158 self._names = [n.strip() for n in names[:self._nfields]]
159 else:
160 self._names = []
161
162 # if the names are not specified, they will be assigned as
163 # "f0, f1, f2,..."
164 # if not enough names are specified, they will be assigned as "f[n],
165 # f[n+1],..." etc. where n is the number of specified names..."
166 self._names += [f'f{i}' for i in range(len(self._names),
167 self._nfields)]
168 # check for redundant names
169 _dup = find_duplicate(self._names)
170 if _dup:
171 raise ValueError(f"Duplicate field names: {_dup}")
172
173 if titles:
174 self._titles = [n.strip() for n in titles[:self._nfields]]
175 else:
176 self._titles = []
177 titles = []
178
179 if self._nfields > len(titles):
180 self._titles += [None] * (self._nfields - len(titles))
181
182 def _createdtype(self, byteorder):
183 dtype = sb.dtype({

Callers 1

__init__Method · 0.95

Calls 3

find_duplicateFunction · 0.85
splitMethod · 0.80
stripMethod · 0.80

Tested by

no test coverage detected