| 86 | # a simple typestring |
| 87 | |
| 88 | def _array_descr(descriptor): |
| 89 | fields = descriptor.fields |
| 90 | if fields is None: |
| 91 | subdtype = descriptor.subdtype |
| 92 | if subdtype is None: |
| 93 | if descriptor.metadata is None: |
| 94 | return descriptor.str |
| 95 | else: |
| 96 | new = descriptor.metadata.copy() |
| 97 | if new: |
| 98 | return (descriptor.str, new) |
| 99 | else: |
| 100 | return descriptor.str |
| 101 | else: |
| 102 | return (_array_descr(subdtype[0]), subdtype[1]) |
| 103 | |
| 104 | names = descriptor.names |
| 105 | ordered_fields = [fields[x] + (x,) for x in names] |
| 106 | result = [] |
| 107 | offset = 0 |
| 108 | for field in ordered_fields: |
| 109 | if field[1] > offset: |
| 110 | num = field[1] - offset |
| 111 | result.append(('', f'|V{num}')) |
| 112 | offset += num |
| 113 | elif field[1] < offset: |
| 114 | raise ValueError( |
| 115 | "dtype.descr is not defined for types with overlapping or " |
| 116 | "out-of-order fields") |
| 117 | if len(field) > 3: |
| 118 | name = (field[2], field[3]) |
| 119 | else: |
| 120 | name = field[2] |
| 121 | if field[0].subdtype: |
| 122 | tup = (name, _array_descr(field[0].subdtype[0]), |
| 123 | field[0].subdtype[1]) |
| 124 | else: |
| 125 | tup = (name, _array_descr(field[0])) |
| 126 | offset += field[0].itemsize |
| 127 | result.append(tup) |
| 128 | |
| 129 | if descriptor.itemsize > offset: |
| 130 | num = descriptor.itemsize - offset |
| 131 | result.append(('', f'|V{num}')) |
| 132 | |
| 133 | return result |
| 134 | |
| 135 | # Build a new array from the information in a pickle. |
| 136 | # Note that the name numpy.core._internal._reconstruct is embedded in |