List#

class dataframely.List(
inner: Column,
*,
nullable: bool = False,
primary_key: bool = False,
check: Callable[[Expr], Expr] | Sequence[Callable[[Expr], Expr]] | Mapping[str, Callable[[Expr], Expr]] | None = None,
alias: str | None = None,
min_length: int | None = None,
max_length: int | None = None,
metadata: dict[str, Any] | None = None,
)[source]#

A list column.

Parameters:
  • inner – The inner column type. If this type has primary_key=True set, all list items are required to be unique. If the inner type is a struct and any of the struct fields have primary_key=True set, these fields must be unique across all list items. Note that if the struct itself has primary_key=True set, the fields’ settings do not take effect.

  • nullable – Whether this column may contain null values. Explicitly set nullable=True if you want your column to be nullable. In a future release, nullable=False will be the default if nullable is not specified.

  • primary_key – Whether this column is part of the primary key of the schema.

  • check – A custom rule or multiple rules to run for this column. This can be: - A single callable that returns a non-aggregated boolean expression. The name of the rule is derived from the callable name, or defaults to “check” for lambdas. - A list of callables, where each callable returns a non-aggregated boolean expression. The name of the rule is derived from the callable name, or defaults to “check” for lambdas. Where multiple rules result in the same name, the suffix __i is appended to the name. - A dictionary mapping rule names to callables, where each callable returns a non-aggregated boolean expression. All rule names provided here are given the prefix "check_".

  • alias – An overwrite for this column’s name which allows for using a column name that is not a valid Python identifier. Especially note that setting this option does _not_ allow to refer to the column with two different names, the specified alias is the only valid name.

  • metadata – A dictionary of metadata to attach to the column.

Attributes:

col

Obtain a Polars column expression for the column.

dtype

The polars dtype equivalent of this column definition's data type.

name

Get the name of the column in a schema.

Methods:

sample

Sample random elements adhering to the constraints of this column.

property col: Expr#

Obtain a Polars column expression for the column.

property dtype: DataType#

The polars dtype equivalent of this column definition’s data type.

This is primarily used for creating empty data frames with an appropriate schema. Thus, it should describe the default dtype equivalent if this data type encompasses multiple underlying data types.

property name: str#

Get the name of the column in a schema.

sample(
generator: Generator,
n: int = 1,
) Series[source]#

Sample random elements adhering to the constraints of this column.

Parameters:
  • generator – The generator to use for sampling elements.

  • n – The number of elements to sample.

Returns:

A series with the predefined number of elements. All elements are guaranteed to adhere to the column’s constraints.

Raises:

ValueError – If this column has a custom check. In this case, random values cannot be guaranteed to adhere to the column’s constraints while providing any guarantees on the computational complexity.