accepted_range
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
| 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({"a": [1, 2, 3]})
>>> df.pipe(plg.accepted_range, {"a": (0, 2)})
Traceback (most recent call last):
...
pelage.types.PolarsAssertError: Details
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ i64 │
╞═════╡
│ 3 │
└─────┘
Error with the DataFrame passed to the check function:
--> Some values are beyond the acceptable ranges defined>>> df.pipe(plg.accepted_range, {"a": (1, 3)})
shape: (3, 1)
┌─────┐
│ a │
│ --- │
│ i64 │
╞═════╡
│ 1 │
│ 2 │
│ 3 │
└─────┘Examples with string containing columns and specifying boundaries:
>>> df = pl.DataFrame({"a": ["b", "c"]})
>>> df.pipe(plg.accepted_range, {"a": (pl.lit("a"), pl.lit("d"), "right")})
shape: (2, 1)
┌─────┐
│ a │
│ --- │
│ str │
╞═════╡
│ b │
│ c │
└─────┘
>>> df.pipe(plg.accepted_range, {"a": (pl.lit("a"), pl.lit("d"), "left")})
shape: (2, 1)
┌─────┐
│ a │
│ --- │
│ str │
╞═════╡
│ b │
│ c │
└─────┘