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

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

maintains_relationships

checks.maintains_relationships(data, other_df, column)

Function to help ensuring that set of values in selected column remains the same in both DataFrames. This helps to maintain referential integrity.

Parameters

data: PolarsLazyOrDataFrame

Dataframe after transformation

other_df: Union[pl.DataFrame, pl.LazyFrame]

Distant dataframe usually the one before transformation

column: str

Column to check for keys/ids

Returns

Type Description
PolarsLazyOrDataFrame The original polars DataFrame or LazyFrame when the check passes

Examples

>>> import polars as pl
>>> import pelage as plg
>>> initial_df = pl.DataFrame({"a": ["a", "b"]})
>>> final_df = pl.DataFrame({"a": ["a", "b"]})
>>> final_df.pipe(plg.maintains_relationships, initial_df, "a")
shape: (2, 1)
┌─────┐
│ a   │
│ --- │
│ str │
╞═════╡
│ a   │
│ b   │
└─────┘
>>> final_df = pl.DataFrame({"a": ["a"]})
>>> final_df.pipe(plg.maintains_relationships, initial_df, "a")
Traceback (most recent call last):
...
pelage.checks.PolarsAssertError: Details
Error with the DataFrame passed to the check function:
--> Some values were removed from col 'a', for ex: ('b',)
accepted_range
column_is_within_n_std