polars_xdt.is_workday#

polars_xdt.is_workday(expr: IntoExpr, *, weekend: Sequence[str] = ('Sat', 'Sun'), holidays: Sequence[date] | None = None) pl.Expr#

Determine whether a day is a workday.

Parameters:
expr

Input expression.

weekend

The days of the week that are considered weekends. Defaults to (“Sat”, “Sun”).

holidays

The holidays to exclude from the calculation. Defaults to None. This should be a list of datetime.date s.

Returns:
polars.Expr

Examples

>>> from datetime import date
>>> import polars as pl
>>> import polars_xdt as xdt
>>> df = pl.DataFrame(
...     {
...         "date": [
...             date(2023, 1, 4),
...             date(2023, 5, 1),
...             date(2023, 9, 9),
...         ],
...     }
... )
>>> df.with_columns(is_workday=xdt.is_workday("date"))
shape: (3, 2)
┌────────────┬────────────┐
│ date       ┆ is_workday │
│ ---        ┆ ---        │
│ date       ┆ bool       │
╞════════════╪════════════╡
│ 2023-01-04 ┆ true       │
│ 2023-05-01 ┆ true       │
│ 2023-09-09 ┆ false      │
└────────────┴────────────┘