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

Function _get_fieldspec

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

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