accepted_range
checks.accepted_range(data, items)
Check that all the values from specifed columns in the dict items
are within the indicated range.
Parameters
data: PolarsLazyOrDataFrame
items: Dict[str, PolarsColumnBounds]
-
Any type of inputs that match the following signature:
column_name: (boundaries)
where boundaries is compatible with the Polars methodis_between()
syntax.For example:
{ "col_a": (low, high), "col_b", (low_b, high_b, "right"), "col_c", (low_c, high_c, "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({"a": [1, 2, 3]})
>>> df.pipe(plg.accepted_range, {"a": (0, 2)})
Traceback (most recent call last):
...
pelage.checks.PolarsAssertError: Details1, 1)
shape: (
┌─────┐
│ a │--- │
│
│ i64 │
╞═════╡3 │
│
└─────┘with the DataFrame passed to the check function:
Error -->Some values are beyond the acceptable ranges defined
>>> df.pipe(plg.accepted_range, {"a": (1, 3)})
3, 1)
shape: (
┌─────┐
│ a │--- │
│
│ i64 │
╞═════╡1 │
│ 2 │
│ 3 │
│
└─────┘>>> df = pl.DataFrame({"a": ["b", "c"]})
>>> df.pipe(plg.accepted_range, {"a": (pl.lit("a"), pl.lit("d"), "right")})
2, 1)
shape: (
┌─────┐
│ a │--- │
│ str │
│
╞═════╡
│ b │
│ c │
└─────┘>>> df.pipe(plg.accepted_range, {"a": (pl.lit("a"), pl.lit("d"), "left")})
2, 1)
shape: (
┌─────┐
│ a │--- │
│ str │
│
╞═════╡
│ b │
│ c │ └─────┘