has_dtypes
checks.has_dtypes(data, items)
Check that the columns have the expected types
Parameters
data: PolarsLazyOrDataFrame
-
Polars DataFrame or LazyFrame containing data to check.
items: Dict[str, PolarsDataType]
-
A dictionnary of column name with their expected polars data type:
{ "col_a": pl.String, "col_b": pl.Int64, "col_c": pl.Float64, ... }
Returns
Type | Description |
---|---|
PolarsLazyOrDataFrame | The original polars DataFrame or LazyFrame when the check passes |
Examples
>>> import polars as pl
>>> from pelage import checks
>>> df = pl.DataFrame({
"name": ["Alice", "Bob", "Charlie"],
... "age": [20, 30, 40],
... "city": ["New York", "London", "Paris"],
...
... })>>> checks.has_dtypes(df, {
"name": pl.String,
... "age": pl.Int64,
... "city": pl.String,
...
... })3, 3)
shape: (
┌─────────┬─────┬──────────┐
│ name ┆ age ┆ city │--- ┆ --- ┆ --- │
│ str ┆ i64 ┆ str │
│
╞═════════╪═════╪══════════╡20 ┆ New York │
│ Alice ┆ 30 ┆ London │
│ Bob ┆ 40 ┆ Paris │
│ Charlie ┆
└─────────┴─────┴──────────┘>>> checks.has_dtypes(df, {
"age": pl.String,
... "city": pl.Int64,
...
... })
Traceback (most recent call last):
...
pelage.checks.PolarsAssertError: Detailswith the DataFrame passed to the check function:
Error -->Some columns don't have the expected type:
column='age', expected_type=String, real_dtype=Int64
='city', expected_type=Int64, real_dtype=String column