pandera.backends.narwhals.checks.NarwhalsCheckBackend

class pandera.backends.narwhals.checks.NarwhalsCheckBackend(check)[source]

Check backend for Narwhals.

Initializes a check backend object.

Methods

__init__(check)[source]

Initializes a check backend object.

aggregate(check_obj)[source]

Implements aggregation behavior for check object.

apply(check_obj)[source]

Apply check function — dispatch on self.check.native flag.

apply_groupby(check_obj)[source]

Run a groupby= check by building the pandas group dict.

Only supported for pandas-like eager frames. The user check function receives the same dict it would under the native pandas backend and typically returns a scalar boolean (or a per-group Series/dict of booleans, which is reduced to a single pass/fail).

groupby(check_obj)[source]

Implements groupby behavior for check object.

Column-check-groups (groupby=) are a pandas-semantic feature: the user check function receives a dict mapping group key to the native pandas Series/DataFrame for that group. Narwhals has no equivalent, so for pandas-like eager frames we group the native frame with pandas and build the same dict the native pandas backend produces.

Parameters:

check_obj – a native pandas-like frame (already unwrapped).

postprocess(check_obj, check_output)[source]

Postprocesses the result of applying the check function.

postprocess_bool_output(check_obj, check_output)[source]

Postprocesses bool check output into a CheckResult.

Return type:

CheckResult

postprocess_expr_output(check_obj, expr)[source]

Postprocesses nw.Expr check output into a CheckResult.

Stores the original expr as check_output and defers failure_cases computation entirely — no wide table is built during the check loop.

When drop_invalid_rows=True: failure_cases are never needed, so this avoids all per-check materialization. When SchemaErrors is raised: failure_cases_metadata() in base.py reconstructs them from the stored expr exactly once.

check_passed is computed via a single-column select+aggregate (frame.select(expr) → apply ignore_na on column → .select(.all())) rather than frame.with_columns(expr) which keeps all original columns.

ignore_na is applied at the column level AFTER evaluation rather than as expr | expr.is_null() — the latter causes ibis to produce incorrect SQL (isnull() on an expression before binding returns True for all rows on some SQL backends, because the expression is treated as nullable).

For pandas-like frames, ignore_na additionally ORs in the input column’s nullness: pandas comparisons on NaN yield False instead of propagating null (unlike polars/ibis), so output-nullness alone would treat missing values as check failures.

Return type:

CheckResult

postprocess_lazyframe_output(check_obj, check_output)[source]

Postprocesses LazyFrame check output into a CheckResult.

Return type:

CheckResult

preprocess(check_obj, key)[source]

Preprocesses a check object before applying the check function.

query(check_obj)[source]

Implements querying behavior to produce subset of check object.

__call__(check_obj, key=None)[source]

Call self as a function.

Return type:

CheckResult