polars.testing.parametric.columns(cols: Optional[Union[int, Sequence[str]]] = None, *, dtype: Optional[Union[Type[DataType], DataType, Sequence[Union[Type[DataType], DataType]]]] = None, min_cols: int | None = 0, max_cols: int | None = 8, unique: bool = False) list[polars.testing._parametric.column][source]#

Define multiple columns for use with the @dataframes strategy.

Generate a fixed sequence of column objects suitable for passing to the @dataframes strategy, or using standalone (note that this function is not itself a strategy).

cols{int, [str]}, optional

integer number of cols to create, or explicit list of column names. if omitted a random number of columns (between mincol and max_cols) are created.

dtypedtype, optional

a single dtype for all cols, or list of dtypes (the same length as cols). if omitted, each generated column is assigned a random dtype.

min_colsint, optional

if not passing an exact size, can set a minimum here (defaults to 0).

max_colsint, optional

if not passing an exact size, can set a maximum value here (defaults to MAX_COLS).

uniquebool, optional

indicate if the values generated for these columns should be unique (per-column).


Additional control is available by creating a sequence of columns explicitly, using the column class (an especially useful option is to override the default data-generating strategy for a given col/dtype).


>>> from polars.testing.parametric import columns
>>> from string import punctuation
>>> def test_special_char_colname_init() -> None:
...     cols = [(c.name, c.dtype) for c in columns(punctuation)]
...     df = pl.DataFrame(columns=cols)
...     assert len(cols) == len(df.columns)
...     assert 0 == len(df.rows())
>>> from polars.testing.parametric import columns
>>> from hypothesis import given
>>> @given(dataframes(columns(["x", "y", "z"], unique=True)))
... def test_unique_xyz(df: pl.DataFrame) -> None:
...     assert_something(df)