Skip to content

Struct and Array

Struct

Bases: Column[StructType], _Base

columns property

columns: list[Column]

generate_schema classmethod

generate_schema()

columndict

columndict() -> dict[str, Column]

to_spark

to_spark() -> Column

group

group() -> Self

Mark column as a group key for use in an aggregate DataFrame constructor.

Example::

class Agg(ts.DataFrame):
    name: ts.String
    total: ts.Int

Agg(df, name=df.name.group(), total=ts.sum(df.age))

The returned value is a _GroupColumn sentinel. Arithmetic and comparison operations on it raise TypeError — operate on the field after construction instead.

cast

cast(dataType: BooleanType) -> Bool
cast(dataType: BinaryType) -> Binary
cast(dataType: DateType) -> Date
cast(dataType: DecimalType) -> Decimal
cast(dataType: DoubleType) -> Double
cast(dataType: FloatType) -> Float
cast(dataType: IntegerType) -> Integer
cast(dataType: LongType) -> Long
cast(dataType: ShortType) -> Short
cast(dataType: StringType) -> String
cast(dataType: TimestampType) -> Timestamp
cast(dataType: TimestampNTZType) -> TimestampNTZ
cast(dataType: ArrayType) -> Array[Any]
cast(dataType: DataType) -> Column[Any]
cast(dataType: U) -> Column[U]

alias

alias(alias: str, **kwargs) -> Self

name

name(alias: str, **kwargs) -> Self

isNull

isNull() -> Bool

isNotNull

isNotNull() -> Bool

like

like(pattern: str) -> Bool

over

over(window: WindowSpec | WindowSpec) -> Self

Evaluate this column over a window, like pyspark.sql.Column.over.

An aggregate (tsf.sum(col).over(w)) becomes a plain column of the same type, so the DataFrame constructor projects it instead of grouping.

desc

desc() -> Self

asc

asc() -> Self

isin

isin(*cols: Any) -> Bool

rlike

rlike(item: str) -> Bool

between

between(lowerBound: Self, upperBound: Self) -> Bool

wrap classmethod

wrap(c: Column) -> Self

fields

fields() -> dict[str, Column]

null classmethod

null() -> Self

from_json classmethod

from_json(
    json: Column[StringType],
    options: dict[str, str] | None = None,
) -> Self

Array

Bases: Column[ArrayType]

empty classmethod

empty() -> Self

null classmethod

null() -> Self

from_json classmethod

from_json(
    json: Column[StringType],
    options: dict[str, str] | None = None,
) -> Self

generate_schema classmethod

generate_schema() -> ArrayType

getItem

getItem(key: int) -> T

explode

explode() -> T
explode(access: Callable[[T], U]) -> U
explode(access: Callable[[T], Any] | None = None) -> Any

One row per array element.

Without access the result is the element itself. With access, the result is whatever access builds from the element, e.g. df.areas.explode(lambda a: a.id). The access is deferred: the element only exists once the explode has run, so any expression on it — field access, casts, functions — must go inside access.

Several explode() calls on the same array column share one explode.