Pelage: Defensive analysis for Polars
  • Get started
  • API Reference
  • Examples
  • Coming from dbt
  • Git
  1. Checks with group_by
  2. mutually_exclusive_ranges
  • API Reference
  • Check functions
    • has_columns
    • has_dtypes
    • has_no_nulls
    • has_no_infs
    • unique
    • unique_combination_of_columns
    • accepted_values
    • not_accepted_values
    • accepted_range
    • maintains_relationships
    • column_is_within_n_std
    • custom_check
  • Checks with group_by
    • has_shape
    • at_least_one
    • not_constant
    • not_null_proportion
    • has_mandatory_values
    • mutually_exclusive_ranges
    • is_monotonic
  • Exceptions
    • PolarsAssertError

On this page

  • mutually_exclusive_ranges
    • Parameters
    • Returns
    • Examples
  1. Checks with group_by
  2. mutually_exclusive_ranges

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],
...     ],
...     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.checks.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'
has_mandatory_values
is_monotonic