pyarrow.struct#

pyarrow.struct(fields)#

Create StructType instance from fields.

A struct is a nested type parameterized by an ordered sequence of types (which can all be distinct), called its fields.

Parameters:
fieldsiterable of Fields or tuples, or mapping of strings to DataTypes

Each field must have a UTF8-encoded name, and these field names are part of the type metadata.

Returns:
typeDataType

Examples

Create an instance of StructType from an iterable of tuples:

>>> import pyarrow as pa
>>> fields = [
...     ('f1', pa.int32()),
...     ('f2', pa.string()),
... ]
>>> struct_type = pa.struct(fields)
>>> struct_type
StructType(struct<f1: int32, f2: string>)

Retrieve a field from a StructType:

>>> struct_type[0]
pyarrow.Field<f1: int32>
>>> struct_type['f1']
pyarrow.Field<f1: int32>

Create an instance of StructType from an iterable of Fields:

>>> fields = [
...     pa.field('f1', pa.int32()),
...     pa.field('f2', pa.string(), nullable=False),
... ]
>>> pa.struct(fields)
StructType(struct<f1: int32, f2: string not null>)