cudf.StructDtype#
- class cudf.StructDtype(fields)#
Type to represent a struct data.
- Parameters
- fieldsdict
A mapping of field names to dtypes, the dtypes can themselves be of
StructDtype
too.
Examples
>>> import cudf >>> struct_dtype = cudf.StructDtype({"a": "int64", "b": "string"}) >>> struct_dtype StructDtype({'a': dtype('int64'), 'b': dtype('O')})
A nested
StructDtype
can also be constructed in the following way:>>> nested_struct_dtype = cudf.StructDtype({"dict_data": struct_dtype, "c": "uint8"}) >>> nested_struct_dtype StructDtype({'dict_data': StructDtype({'a': dtype('int64'), 'b': dtype('O')}), 'c': dtype('uint8')})
Attributes
Returns an ordered dict of column name and dtype key-value.
Methods
from_arrow
(typ)Convert a
pyarrow.StructType
toStructDtype
.to_arrow
()Convert a
StructDtype
to apyarrow.StructType
.- property fields#
Returns an ordered dict of column name and dtype key-value.
Examples
>>> import cudf >>> struct_dtype = cudf.StructDtype({"a": "int64", "b": "string"}) >>> struct_dtype StructDtype({'a': dtype('int64'), 'b': dtype('O')}) >>> struct_dtype.fields {'a': dtype('int64'), 'b': dtype('O')}
- classmethod from_arrow(typ)#
Convert a
pyarrow.StructType
toStructDtype
.Examples
>>> import cudf >>> import pyarrow as pa >>> pa_struct_type = pa.struct({'x': pa.int32(), 'y': pa.string()}) >>> pa_struct_type StructType(struct<x: int32, y: string>) >>> cudf.StructDtype.from_arrow(pa_struct_type) StructDtype({'x': dtype('int32'), 'y': dtype('O')})
- to_arrow()#
Convert a
StructDtype
to apyarrow.StructType
.Examples
>>> import cudf >>> struct_type = cudf.StructDtype({"x": "int32", "y": "string"}) >>> struct_type StructDtype({'x': dtype('int32'), 'y': dtype('O')}) >>> struct_type.to_arrow() StructType(struct<x: int32, y: string>)