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

Function _get_fieldspec

numpy/lib/recfunctions.py:71–100  ·  view source on GitHub ↗

Produce a list of name/dtype pairs corresponding to the dtype fields Similar to dtype.descr, but the second item of each tuple is a dtype, not a string. As a result, this handles subarray dtypes Can be passed to the dtype constructor to reconstruct the dtype, noting that this

(dtype)

Source from the content-addressed store, hash-verified

69
70
71def _get_fieldspec(dtype):
72 """
73 Produce a list of name/dtype pairs corresponding to the dtype fields
74
75 Similar to dtype.descr, but the second item of each tuple is a dtype, not a
76 string. As a result, this handles subarray dtypes
77
78 Can be passed to the dtype constructor to reconstruct the dtype, noting that
79 this (deliberately) discards field offsets.
80
81 Examples
82 --------
83 >>> import numpy as np
84 >>> dt = np.dtype([(('a', 'A'), np.int64), ('b', np.double, 3)])
85 >>> dt.descr
86 [(('a', 'A'), '<i8'), ('b', '<f8', (3,))]
87 >>> _get_fieldspec(dt)
88 [(('a', 'A'), dtype('int64')), ('b', dtype(('<f8', (3,))))]
89
90 """
91 if dtype.names is None:
92 # .descr returns a nameless field, so we should too
93 return [('', dtype)]
94 else:
95 fields = ((name, dtype.fields[name]) for name in dtype.names)
96 # keep any titles, if present
97 return [
98 (name if len(f) == 2 else (f[2], name), f[0])
99 for name, f in fields
100 ]
101
102
103def get_names(adtype):

Callers 4

_zip_dtypeFunction · 0.85
append_fieldsFunction · 0.85
stack_arraysFunction · 0.85
join_byFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…