pandera.backends.narwhals.base.NarwhalsSchemaBackend¶
- class pandera.backends.narwhals.base.NarwhalsSchemaBackend[source]¶
Base schema backend for Narwhals-backed DataFrames.
Provides shared helpers used by ColumnBackend (components.py) and DataFrameSchemaBackend (container.py).
Methods
- drop_invalid_rows(check_obj, error_handler)[source]¶
Remove invalid rows — pure Narwhals, no backend delegation.
Builds a pass-mask boolean column per check_output, combines with nw.all_horizontal, filters, and drops the temporary columns. Works identically for polars lazy frames and ibis tables.
Two check_output conventions are handled: - nw.Expr (DATAFRAME_CHECK path): True=row passes check - nw.LazyFrame/DataFrame with CHECK_OUTPUT_KEY=True meaning “failed”
(SERIES_CONTAINS_NULLS / check_nullable): True=row has null (failing). Reconstructed as ~col.is_null() from err.schema.selector.
- Parameters:
check_obj – The frame to filter.
error_handler – ErrorHandler whose schema_errors carry check_output.
- Returns:
Filtered frame with only rows where all checks passed.
- failure_cases_metadata(schema_name, schema_errors)[source]¶
Create failure cases metadata required for SchemaErrors exception.
Backend-agnostic: returns native ibis.Table for ibis inputs and pl.LazyFrame/pl.DataFrame for polars inputs — no forced polars conversion, no Arrow roundtrip for lazy/SQL backends.
- Return type:
FailureCaseMetadata
- is_float_dtype(check_obj, col_name)[source]¶
Return True if the column col_name has a float dtype.
Uses collect_schema() so it works on both LazyFrame and DataFrame without triggering full materialization.
- run_check(check_obj, schema, check, check_index, *args)[source]¶
Execute a single Check object and return a CoreCheckResult.
Single unified code path — no _is_ibis_result bifurcation. Materializes only the scalar passed bool via _materialize(check_passed). failure_cases and check_output stay as Narwhals wrappers in the returned CoreCheckResult; callers (failure_cases_metadata) materialize as needed.
- subsample(check_obj, head=None, tail=None, sample=None, random_state=None)[source]¶
Return a (possibly subsampled) version of check_obj.
Never materializes check_obj — delegates directly to .head()/.tail() so the result stays lazy (nw.LazyFrame) for Polars inputs.
- Parameters:
- Raises:
NotImplementedError – If sample is not None, or if tail= is requested on a SQL-lazy backend (ibis.Table) that does not support TAIL without forced full ordering.