pyarrow.StructType¶
- class pyarrow.StructType¶
Bases:
DataType
Concrete class for struct data types.
StructType
supports direct indexing using[...]
(implemented via__getitem__
) to access its fields. It will return the struct field with the given index or name.Examples
>>> import pyarrow as pa
Accessing fields using direct indexing:
>>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()}) >>> struct_type[0] pyarrow.Field<x: int32> >>> struct_type['y'] pyarrow.Field<y: string>
Accessing fields using
field()
:>>> struct_type.field(1) pyarrow.Field<y: string> >>> struct_type.field('x') pyarrow.Field<x: int32>
# Creating a schema from the struct type’s fields: >>> pa.schema(list(struct_type)) x: int32 y: string
- __init__(*args, **kwargs)¶
Methods
__init__
(*args, **kwargs)equals
(self, other, *[, check_metadata])Return true if type is equivalent to passed value.
field
(self, i)Select a field by its column name or numeric index.
get_all_field_indices
(self, name)Return sorted list of indices for the fields with the given name.
get_field_index
(self, name)Return index of the unique field with the given name.
to_pandas_dtype
(self)Return the equivalent NumPy / Pandas dtype.
Attributes
Number of data buffers required to construct Array type excluding children.
The number of child fields.
- bit_width¶
- equals(self, other, *, check_metadata=False)¶
Return true if type is equivalent to passed value.
- field(self, i) Field ¶
Select a field by its column name or numeric index.
- Parameters:
- Returns:
Examples
>>> import pyarrow as pa >>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()})
Select the second field:
>>> struct_type.field(1) pyarrow.Field<y: string>
Select the field named ‘x’:
>>> struct_type.field('x') pyarrow.Field<x: int32>
- get_all_field_indices(self, name)¶
Return sorted list of indices for the fields with the given name.
- get_field_index(self, name)¶
Return index of the unique field with the given name.
- id¶
- num_buffers¶
Number of data buffers required to construct Array type excluding children.
- num_fields¶
The number of child fields.
- to_pandas_dtype(self)¶
Return the equivalent NumPy / Pandas dtype.