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)
| 69 | |
| 70 | |
| 71 | def _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 | |
| 103 | def get_names(adtype): |
no outgoing calls
no test coverage detected
searching dependent graphs…