polars_xdt.date_range#

polars_xdt.date_range(start: date | datetime | IntoExprColumn, end: date | datetime | IntoExprColumn, interval: str | timedelta = '1d', *, closed: ClosedInterval = 'both', eager: Literal[False] = False, weekend: Sequence[str] = ('Sat', 'Sun'), holidays: Sequence[date] | None = None) Expr#
polars_xdt.date_range(start: date | IntoExprColumn, end: date | IntoExprColumn, interval: str | timedelta = '1d', *, closed: ClosedInterval = 'both', eager: Literal[True], weekend: Sequence[str] = ('Sat', 'Sun'), holidays: Sequence[date] | None = None) Series
polars_xdt.date_range(start: date | IntoExprColumn, end: date | IntoExprColumn, interval: str | timedelta = '1d', *, closed: ClosedInterval = 'both', eager: bool = False, weekend: Sequence[str] = ('Sat', 'Sun'), holidays: Sequence[date] | None = None) Series | Expr

Create a range of dates with a given interval and filter out weekends and holidays.

Parameters:
start

Lower bound of the date range.

end

Upper bound of the date range.

interval

Interval of the range periods, specified as a Python timedelta object or using the Polars duration string language (see “Notes” section below).

To create a month-end date series, combine with Expr.dt.month_end() (see “Examples” section below).

closed{‘both’, ‘left’, ‘right’, ‘none’}

Define which sides of the range are closed (inclusive).

eager

Evaluate immediately and return a Series. If set to False (default), return an expression instead.

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:
Expr or Series

Column of data type Date.

Examples

>>> from datetime import date
>>> import polars as pl
>>> import polars_xdt
>>> pl.DataFrame(
...     {
...         "date": polars_xdt.date_range(
...             date(2023, 1, 1), date(2023, 1, 10), "1bd", eager=True
...         ),
...     }
... )
shape: (7, 1)
┌────────────┐
│ date       │
│ ---        │
│ date       │
╞════════════╡
│ 2023-01-02 │
│ 2023-01-03 │
│ 2023-01-04 │
│ 2023-01-05 │
│ 2023-01-06 │
│ 2023-01-09 │
│ 2023-01-10 │
└────────────┘