mutually_exclusive_ranges
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
| Name | 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],
... ],
... schema=["a", "b"], orient="row"
... )
>>> df.pipe(plg.mutually_exclusive_ranges, low_bound="a", high_bound="b")
shape: (2, 2)
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1 ┆ 2 │
│ 3 ┆ 4 │
└─────┴─────┘>>> df = pl.DataFrame(
... [
... [1, 3],
... [2, 4],
... [5, 7],
... [6, 8],
... [9, 9],
... ],
... schema=["a", "b"],
... orient="row",
... )
>>> df.pipe(plg.mutually_exclusive_ranges, low_bound="a", high_bound="b")
Traceback (most recent call last):
...
pelage.types.PolarsAssertError: Details
shape: (4, 3)
┌───────┬─────┬─────┐
│ index ┆ a ┆ b │
│ --- ┆ --- ┆ --- │
│ u32 ┆ i64 ┆ i64 │
╞═══════╪═════╪═════╡
│ 0 ┆ 1 ┆ 3 │
│ 1 ┆ 2 ┆ 4 │
│ 2 ┆ 5 ┆ 7 │
│ 3 ┆ 6 ┆ 8 │
└───────┴─────┴─────┘
Error with the DataFrame passed to the check function:
--> There were overlapping intervals:
DataFrame was sorted by: ['a', 'b'],
Interval columns: low_bound='a', high_bound='b'