polars.datatypes.Struct#

class polars.datatypes.Struct(fields: Sequence[Field] | SchemaDict)[source]#

Struct composite type.

Parameters:
fields

The fields that make up the struct. Can be either a sequence of Field objects or a mapping of column names to data types.

Examples

Initialize using a dictionary:

>>> dtype = pl.Struct({"a": pl.Int8, "b": pl.List(pl.String)})
>>> dtype
Struct({'a': Int8, 'b': List(String)})

Initialize using a list of Field objects:

>>> dtype = pl.Struct([pl.Field("a", pl.Int8), pl.Field("b", pl.List(pl.String))])
>>> dtype
Struct({'a': Int8, 'b': List(String)})

When initializing a Series, Polars can infer a struct data type from the data.

>>> s = pl.Series([{"a": 1, "b": ["x", "y"]}, {"a": 2, "b": ["z"]}])
>>> s
shape: (2,)
Series: '' [struct[2]]
[
        {1,["x", "y"]}
        {2,["z"]}
]
>>> s.dtype
Struct({'a': Int64, 'b': List(String)})
__init__(fields: Sequence[Field] | SchemaDict)[source]#

Methods

__init__(fields)

base_type()

Return this DataType's fundamental/root type class.

is_(other)

Check if this DataType is the same as another DataType.

is_decimal()

Check whether the data type is a decimal type.

is_float()

Check whether the data type is a floating point type.

is_integer()

Check whether the data type is an integer type.

is_nested()

Check whether the data type is a nested type.

is_not(other)

Check if this DataType is NOT the same as another DataType.

is_numeric()

Check whether the data type is a numeric type.

is_signed_integer()

Check whether the data type is a signed integer type.

is_temporal()

Check whether the data type is a temporal type.

is_unsigned_integer()

Check whether the data type is an unsigned integer type.

to_schema()

Return Struct dtype as a schema dict.

Attributes

fields