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

Function get_fieldstructure

numpy/lib/recfunctions.py:226–271  ·  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

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

Callers 2

find_duplicatesFunction · 0.85

Calls 2

updateMethod · 0.80
getMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…