unique_combination_of_columns
checks.unique_combination_of_columns(data, columns=None)
Ensure that the selected column have a unique combination per row.
This function is particularly helpful to establish the granularity of a dataframe, i.e. this is a row oriented check.
Parameters
data: PolarsLazyOrDataFrame
-
description
columns: Optional[PolarsColumnType] = None
-
Columns to consider for row unicity. By default, all columns are checked.
Returns
Type | Description |
---|---|
PolarsLazyOrDataFrame | The original polars DataFrame or LazyFrame when the check passes |
Examples
>>> import polars as pl
>>> import pelage as plg
>>> df = pl.DataFrame({"a": ["a", "a"], "b": [1, 2]})
>>> df.pipe(plg.unique_combination_of_columns, ["a", "b"])
2, 2)
shape: (
┌─────┬─────┐
│ a ┆ b │--- ┆ --- │
│ str ┆ i64 │
│
╞═════╪═════╡1 │
│ a ┆ 2 │
│ a ┆
└─────┴─────┘>>> bad = pl.DataFrame({"a": ["X", "X"]})
>>> bad.pipe(plg.unique_combination_of_columns, "a")
Traceback (most recent call last):
...
pelage.checks.PolarsAssertError: Details1, 2)
shape: (
┌─────┬─────┐len │
│ a ┆ --- ┆ --- │
│ str ┆ u32 │
│
╞═════╪═════╡2 │
│ X ┆
└─────┴─────┘with the DataFrame passed to the check function:
Error -->Some combinations of columns are not unique. See above, selected: col("a")