Pelage: Defensive analysis for Polars
  • Get started
  • API Reference
  • Examples
  • Coming from dbt
  • Git
  1. Check functions
  2. accepted_range
  • 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

  • accepted_range
    • Parameters
    • Returns
    • Examples
  1. Check functions
  2. accepted_range

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 method is_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: 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   │
└─────┘
>>> 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   │
└─────┘
not_accepted_values
maintains_relationships