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

Function get_fieldstructure

numpy/lib/recfunctions.py:225–269  ·  view source on GitHub ↗

Returns a dictionary with fields indexing lists of their parent fields. This function is used to simplify access to fields nested in other fields. Parameters ---------- adtype : np.dtype Input datatype lastname : optional Last processed field name (used int

(adtype, lastname=None, parents=None,)

Source from the content-addressed store, hash-verified

223
224
225def get_fieldstructure(adtype, lastname=None, parents=None,):
226 """
227 Returns a dictionary with fields indexing lists of their parent fields.
228
229 This function is used to simplify access to fields nested in other fields.
230
231 Parameters
232 ----------
233 adtype : np.dtype
234 Input datatype
235 lastname : optional
236 Last processed field name (used internally during recursion).
237 parents : dictionary
238 Dictionary of parent fields (used interbally during recursion).
239
240 Examples
241 --------
242 >>> from numpy.lib import recfunctions as rfn
243 >>> ndtype = np.dtype([('A', int),
244 ... ('B', [('BA', int),
245 ... ('BB', [('BBA', int), ('BBB', int)])])])
246 >>> rfn.get_fieldstructure(ndtype)
247 ... # XXX: possible regression, order of BBA and BBB is swapped
248 {'A': [], 'B': [], 'BA': ['B'], 'BB': ['B'], 'BBA': ['B', 'BB'], 'BBB': ['B', 'BB']}
249
250 """
251 if parents is None:
252 parents = {}
253 names = adtype.names
254 for name in names:
255 current = adtype[name]
256 if current.names is not None:
257 if lastname:
258 parents[name] = [lastname, ]
259 else:
260 parents[name] = []
261 parents.update(get_fieldstructure(current, name, parents))
262 else:
263 lastparent = [_ for _ in (parents.get(lastname, []) or [])]
264 if lastparent:
265 lastparent.append(lastname)
266 elif lastname:
267 lastparent = [lastname, ]
268 parents[name] = lastparent or []
269 return parents
270
271
272def _izip_fields_flat(iterable):

Callers 2

find_duplicatesFunction · 0.85

Calls 2

updateMethod · 0.80
getMethod · 0.45

Tested by 1