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