Any#

class dataframely.Any(
*,
check: Callable[[Expr], Expr] | Sequence[Callable[[Expr], Expr]] | Mapping[str, Callable[[Expr], Expr]] | None = None,
alias: str | None = None,
metadata: dict[str, Any] | None = None,
)[source]#

A column with arbitrary type.

As a column with arbitrary type is commonly mapped to the Null type (this is the default in polars and pyarrow for empty columns), dataframely also requires this column to be nullable. Hence, it cannot be used as a primary key.

Parameters:
  • 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.