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

Class format_parser

numpy/_core/records.py:57–193  ·  view source on GitHub ↗

Class to convert formats, names, titles description to a dtype. After constructing the format_parser object, the dtype attribute is the converted data-type: ``dtype = format_parser(formats, names, titles).dtype`` Attributes ---------- dtype : dtype The converte

Source from the content-addressed store, hash-verified

55
56@set_module('numpy.rec')
57class format_parser:
58 """
59 Class to convert formats, names, titles description to a dtype.
60
61 After constructing the format_parser object, the dtype attribute is
62 the converted data-type:
63 ``dtype = format_parser(formats, names, titles).dtype``
64
65 Attributes
66 ----------
67 dtype : dtype
68 The converted data-type.
69
70 Parameters
71 ----------
72 formats : str or list of str
73 The format description, either specified as a string with
74 comma-separated format descriptions in the form ``'f8, i4, S5'``, or
75 a list of format description strings in the form
76 ``['f8', 'i4', 'S5']``.
77 names : str or list/tuple of str
78 The field names, either specified as a comma-separated string in the
79 form ``'col1, col2, col3'``, or as a list or tuple of strings in the
80 form ``['col1', 'col2', 'col3']``.
81 An empty list can be used, in that case default field names
82 ('f0', 'f1', ...) are used.
83 titles : sequence
84 Sequence of title strings. An empty list can be used to leave titles
85 out.
86 aligned : bool, optional
87 If True, align the fields by padding as the C-compiler would.
88 Default is False.
89 byteorder : str, optional
90 If specified, all the fields will be changed to the
91 provided byte-order. Otherwise, the default byte-order is
92 used. For all available string specifiers, see `dtype.newbyteorder`.
93
94 See Also
95 --------
96 numpy.dtype, numpy.typename
97
98 Examples
99 --------
100 >>> import numpy as np
101 >>> np.rec.format_parser(['<f8', '<i4'], ['col1', 'col2'],
102 ... ['T1', 'T2']).dtype
103 dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4')])
104
105 `names` and/or `titles` can be empty lists. If `titles` is an empty list,
106 titles will simply not appear. If `names` is empty, default field names
107 will be used.
108
109 >>> np.rec.format_parser(['f8', 'i4', 'S5'], ['col1', 'col2', 'col3'],
110 ... []).dtype
111 dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')])
112 >>> np.rec.format_parser(['<f8', '<i4', '<S5'], [], []).dtype
113 dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')])
114

Callers 6

__new__Method · 0.85
fromarraysFunction · 0.85
fromrecordsFunction · 0.85
fromstringFunction · 0.85
fromfileFunction · 0.85
arrayFunction · 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…