Create regular date sequences
Build a calendar axis for daily or multi-day analysis.
Polars · Function
Generates a Date range between start and end using a full-day interval. It returns an expression by default or an eagerly evaluated Series when eager=True.
pl.date_range generates dates from a lower bound through an upper bound using a day-based interval. It can return either a lazy expression or, with eager=True, an immediately evaluated Date Series; the interval may be a timedelta or a Polars duration string.
polars.date_range(start: date | datetime | IntoExprColumn, end: date | datetime | IntoExprColumn, interval: str | timedelta = '1d', *, closed: ClosedInterval = 'both', eager: bool = False) → Series | Expr| Name | Type | Description |
|---|---|---|
start | date | datetime | IntoExprColumn | Lower bound of the date range. |
end | date | datetime | IntoExprColumn | Upper bound of the date range. |
interval | str | timedelta = '1d' | Range interval as a Python timedelta or Polars duration string; it must consist of full days. |
closed | ClosedInterval = 'both' | Controls which boundaries are inclusive: both, left, right, or none. |
eager | bool = False | When true, evaluates immediately and returns a Series; otherwise returns an expression. |
Expr or SeriesColumn of data type Date.
import polars as pl
from datetime import date, timedelta
values = pl.date_range(
date(2024, 1, 1),
date(2024, 1, 5),
timedelta(days=2),
eager=True,
)
print(values)Creates and immediately evaluates a Date Series containing dates two days apart, including both endpoints.
Build a calendar axis for daily or multi-day analysis.
Add a generated date column to a DataFrame or lazy pipeline.
Produce a concrete sequence for iteration or inspection.
It accepts date or datetime bounds and returns an Expr by default or a Series when eager=True. The result has Date type, and the interval can be a timedelta or Polars duration string.
Follow-up: How would you make the range exclude the end? Set closed="left", which keeps the lower boundary inclusive and the upper boundary exclusive.
The interval controls the spacing between generated dates and may be supplied as a Python timedelta or Polars duration string. The documented default interval is "1d".
Follow-up: What restriction applies to the interval? It must consist of full days rather than partial-day periods.
The closed argument selects which boundaries are included. It accepts "both", "left", "right", or "none", with "both" as the default.
Follow-up: How would you generate interior dates only? Use closed="none" so neither endpoint is included.
polars.datetime_rangepolars.datetime_rangespolars.date