mutually_exclusive_ranges
checks.mutually_exclusive_ranges(data, low_bound, high_bound, group_by=None)
Ensure that the specified columns contains no overlapping intervals.
Parameters
data: PolarsLazyOrDataFrame
-
Data to check
low_bound: str
-
Name of column containing the lower bound of the interval
high_bound: str
-
Name of column containing the higher bound of the interval
group_by: IntoExpr | Iterable[IntoExpr] = None
-
Parameter compatible with
.over()
function to split the check by groups, by default None
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(
... [1, 2],
... [3, 4],
... [
... ],=["a", "b"], orient="row"
... schema
... )>>> df.pipe(plg.mutually_exclusive_ranges, low_bound="a", high_bound="b")
2, 2)
shape: (
┌─────┬─────┐
│ a ┆ b │--- ┆ --- │
│
│ i64 ┆ i64 │
╞═════╪═════╡1 ┆ 2 │
│ 3 ┆ 4 │
│
└─────┴─────┘>>> df = pl.DataFrame(
... [1, 3],
... [2, 4],
... [5, 7],
... [6, 8],
... [9, 9],
... [
... ],=["a", "b"],
... schema="row",
... orient
... )>>> df.pipe(plg.mutually_exclusive_ranges, low_bound="a", high_bound="b")
Traceback (most recent call last):
...
pelage.checks.PolarsAssertError: Details4, 3)
shape: (
┌───────┬─────┬─────┐
│ index ┆ a ┆ b │--- ┆ --- ┆ --- │
│
│ u32 ┆ i64 ┆ i64 │
╞═══════╪═════╪═════╡0 ┆ 1 ┆ 3 │
│ 1 ┆ 2 ┆ 4 │
│ 2 ┆ 5 ┆ 7 │
│ 3 ┆ 6 ┆ 8 │
│
└───────┴─────┴─────┘with the DataFrame passed to the check function:
Error -->There were overlapping intervals:
sorted by: ['a', 'b'],
DataFrame was ='a', high_bound='b' Interval columns: low_bound