pandera.backends.narwhals.components.ColumnBackend

class pandera.backends.narwhals.components.ColumnBackend[source]

Per-column validation backend for Narwhals-backed DataFrames.

Implements validate, check_nullable, check_unique, check_dtype, run_checks, and run_checks_and_handle_errors — mirroring pandera/backends/polars/components.py but using Narwhals APIs throughout.

Methods

check_dtype(check_obj, schema)[source]

Check that column dtype matches schema.dtype.

Parameters:
  • check_obj – Narwhals LazyFrame containing the column.

  • schema – Schema object with .dtype and .selector attributes.

Return type:

list[CoreCheckResult]

Returns:

List of CoreCheckResult — one entry per column selector.

check_nullable(check_obj, schema)[source]

Check that no null (or NaN for float columns) values exist.

Parameters:
  • check_obj – Narwhals LazyFrame containing the column.

  • schema – Schema object with .nullable and .selector attributes.

Return type:

list[CoreCheckResult]

Returns:

List of CoreCheckResult — one entry per column selector.

check_unique(check_obj, schema)[source]

Check that column values are unique (no duplicates).

Parameters:
  • check_obj – Narwhals LazyFrame containing the column.

  • schema – Schema object with .unique and .selector attributes.

Return type:

list[CoreCheckResult]

Returns:

List of CoreCheckResult — one entry per column selector.

get_regex_columns(schema, check_obj)[source]

Get column names matching a regex pattern.

Return type:

Iterable

run_checks(check_obj, schema)[source]

Execute all Check objects attached to schema and return results.

Parameters:
  • check_obj – Narwhals LazyFrame containing the column.

  • schema – Schema object with .checks list and .selector attribute.

Return type:

list[CoreCheckResult]

Returns:

List of CoreCheckResult, one per check.

run_checks_and_handle_errors(error_handler, schema, check_obj, **subsample_kwargs)[source]

Orchestrate all column checks, collecting errors via ErrorHandler.

Parameters:
  • error_handler (ErrorHandler) – ErrorHandler instance to collect schema errors.

  • schema – Schema object defining column constraints.

  • check_obj – Narwhals LazyFrame containing the column.

  • subsample_kwargs – Keyword arguments forwarded to subsample().

Return type:

ErrorHandler

Returns:

The error_handler with all errors collected.

validate(check_obj, schema, *, head=None, tail=None, sample=None, random_state=None, lazy=False, inplace=False)[source]

Validate a Narwhals-backed frame against a column schema.

Parameters:
  • check_obj – native pl.LazyFrame (or other Narwhals-supported frame)

  • schema – Column schema with checks and constraints

Returns:

validated frame (same type as input)