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

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

has_columns

checks.has_columns(data, names)

Check if a DataFrame has the specified

Parameters

data: PolarsLazyOrDataFrame

The DataFrame to check for column presence.

names: Union[str, List[str]]

The names of the columns to check.

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], "b": ["a", "b", "c"]})
>>> df.pipe(plg.has_columns, "b")
shape: (3, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ str │
╞═════╪═════╡
│ 1   ┆ a   │
│ 2   ┆ b   │
│ 3   ┆ c   │
└─────┴─────┘
>>> df.pipe(plg.has_columns, "c")
Traceback (most recent call last):
    ...
pelage.checks.PolarsAssertError: Details
Error with the DataFrame passed to the check function:
--> Missing columns if the dataframe: {'c'}
>>> df.pipe(plg.has_columns, ["a", "b"])
shape: (3, 2)
┌─────┬─────┐
│ a   ┆ b   │
│ --- ┆ --- │
│ i64 ┆ str │
╞═════╪═════╡
│ 1   ┆ a   │
│ 2   ┆ b   │
│ 3   ┆ c   │
└─────┴─────┘
API Reference
has_dtypes