Skip to content

Enabler

Functions

NameDescription
ensure_columnEnables PySpark functions to accept either column names (as strings) or Column objects.
ensure_listEnsures the input is returned as a list.

ensure_columnfunction#

def ensure_column(*columns: ColumnOrName) -> tuple[Column, ...]

Enables PySpark functions to accept either column names (as strings) or Column objects.

Parameters: columns (ColumnOrName): Column names (as strings) or Column objects to be converted.

Returns: tuple[Column]: A tuple of Column objects.

Example:

>>> ensure_column("col1", "col2", F.col("col3"))
(Column<b'col1'>, Column<b'col2'>, Column<b'col3'>)

ensure_listfunction#

def ensure_list(single_or_list: Any | list[Any]) -> list[Any]

Ensures the input is returned as a list.

If the input is not already a list, it wraps the input in a list. If the input is already a list, it returns the input unchanged.

Parameters

NameTypeDescription
single_or_listUnion[Any, List[Any]]The input which can be a single item or a list of items.

Returns

list[Any]
List[Any]: A list containing the input item(s).