| [ Web Proxy ] |
| Viewing: https://arrow.apache.org/docs/python/generated/pyarrow.StructType.html#pyarrow.StructType | [Back] [Original] |
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 types fields: >>> pa.schema(list(struct_type)) x: int32 y: string
Methods
|
|
|
Return true if type is equivalent to passed value. |
|
Select a field by its column name or numeric index. |
|
Return sorted list of indices for the fields with the given name. |
|
Return index of the unique field with the given name. |
|
Return the equivalent NumPy / Pandas dtype. |
Attributes
Bit width for fixed width type. |
|
Byte width for fixed width type. |
|
Lists all fields within the StructType. |
|
If True, the number of expected buffers is only lower-bounded by num_buffers. |
|
Lists the field names. |
|
Number of data buffers required to construct Array type excluding children. |
|
The number of child fields. |
Bit width for fixed width type.
Examples
>>> import pyarrow as pa
>>> pa.int64()
DataType(int64)
>>> pa.int64().bit_width
64
Byte width for fixed width type.
Examples
>>> import pyarrow as pa
>>> pa.int64()
DataType(int64)
>>> pa.int64().byte_width
8
Return true if type is equivalent to passed value.
Examples
>>> import pyarrow as pa
>>> pa.int64().equals(pa.string())
False
>>> pa.int64().equals(pa.int64())
True
Select a field by its column name or numeric index.
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>
Lists all fields within the StructType.
Examples
>>> import pyarrow as pa
>>> struct_type = pa.struct([('a', pa.int64()), ('b', pa.float64()), ('c', pa.string())])
>>> struct_type.fields
[pyarrow.Field<a: int64>, pyarrow.Field<b: double>, pyarrow.Field<c: string>]
Return sorted list of indices for the fields with the given name.
Examples
>>> import pyarrow as pa
>>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()})
>>> struct_type.get_all_field_indices('x')
[0]
Return index of the unique field with the given name.
strThe name of the field to look up.
intThe index of the field with the given name; -1 if the name isnt found or there are several fields with the given name.
Examples
>>> import pyarrow as pa
>>> struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()})
Index of the field with a name y:
>>> struct_type.get_field_index('y')
1
Index of the field that does not exist:
>>> struct_type.get_field_index('z')
-1
If True, the number of expected buffers is only lower-bounded by num_buffers.
Examples
>>> import pyarrow as pa
>>> pa.int64().has_variadic_buffers
False
>>> pa.string_view().has_variadic_buffers
True
Lists the field names.
Examples
>>> import pyarrow as pa
>>> struct_type = pa.struct([('a', pa.int64()), ('b', pa.float64()), ('c', pa.string())])
>>> struct_type.names
['a', 'b', 'c']
Number of data buffers required to construct Array type excluding children.
Examples
>>> import pyarrow as pa
>>> pa.int64().num_buffers
2
>>> pa.string().num_buffers
3
The number of child fields.
Examples
>>> import pyarrow as pa
>>> pa.int64()
DataType(int64)
>>> pa.int64().num_fields
0
>>> pa.list_(pa.string())
ListType(list<item: string>)
>>> pa.list_(pa.string()).num_fields
1
>>> struct = pa.struct({'x': pa.int32(), 'y': pa.string()})
>>> struct.num_fields
2
Return the equivalent NumPy / Pandas dtype.
Examples
>>> import pyarrow as pa
>>> pa.int64().to_pandas_dtype()
<class 'numpy.int64'>
| Web Proxy Viewer | New URL | Original Page |