polars.date_range#
- polars.date_range(low: Expr, high: datetime.date | datetime.datetime | polars.internals.expr.expr.Expr | str, interval: str | datetime.timedelta, *, lazy: Literal[False] = False, closed: ClosedInterval = 'both', name: str | None = None, time_unit: TimeUnit | None = None, time_zone: str | None = None) Expr [source]#
- polars.date_range(low: datetime.date | datetime.datetime | polars.internals.expr.expr.Expr | str, high: Expr, interval: str | datetime.timedelta, *, lazy: Literal[False] = False, closed: ClosedInterval = 'both', name: str | None = None, time_unit: TimeUnit | None = None, time_zone: str | None = None) Expr
- polars.date_range(low: datetime.date | datetime.datetime | str, high: datetime.date | datetime.datetime | str, interval: str | datetime.timedelta, *, lazy: Literal[False] = False, closed: ClosedInterval = 'both', name: str | None = None, time_unit: TimeUnit | None = None, time_zone: str | None = None) Series
- polars.date_range(low: datetime.date | datetime.datetime | polars.internals.expr.expr.Expr | str, high: datetime.date | datetime.datetime | polars.internals.expr.expr.Expr | str, interval: str | datetime.timedelta, *, lazy: Literal[True], closed: ClosedInterval = 'both', name: str | None = None, time_unit: TimeUnit | None = None, time_zone: str | None = None) Expr
Create a range of type Datetime (or Date).
- Parameters:
- low
Lower bound of the date range, given as a date, datetime, Expr, or column name.
- high
Upper bound of the date range, given as a date, datetime, Expr, or column name.
- interval
Interval periods. It can be a python timedelta object, like
timedelta(days=10)
, or a polars duration string, such as3d12h4m25s
representing 3 days, 12 hours, 4 minutes, and 25 seconds.- lazy:
Return an expression.
- closed{‘both’, ‘left’, ‘right’, ‘none’}
Define whether the temporal window interval is closed or not.
- name
Name of the output Series.
- time_unit{None, ‘ns’, ‘us’, ‘ms’}
Set the time unit.
- time_zone:
Optional timezone
- Returns:
- A Series of type Datetime or Date.
Notes
If both
low
andhigh
are passed as date types (not datetime), and the interval granularity is no finer than 1d, the returned range is also of type date. All other permutations return a datetime Series.Examples
Using polars duration string to specify the interval:
>>> from datetime import date >>> pl.date_range(date(2022, 1, 1), date(2022, 3, 1), "1mo", name="dtrange") shape: (3,) Series: 'dtrange' [date] [ 2022-01-01 2022-02-01 2022-03-01 ]
Using timedelta object to specify the interval:
>>> from datetime import datetime, timedelta >>> pl.date_range( ... datetime(1985, 1, 1), ... datetime(1985, 1, 10), ... timedelta(days=1, hours=12), ... time_unit="ms", ... ) shape: (7,) Series: '' [datetime[ms]] [ 1985-01-01 00:00:00 1985-01-02 12:00:00 1985-01-04 00:00:00 1985-01-05 12:00:00 1985-01-07 00:00:00 1985-01-08 12:00:00 1985-01-10 00:00:00 ]
Specify a time zone
>>> pl.date_range( ... datetime(2022, 1, 1), ... datetime(2022, 3, 1), ... "1mo", ... time_zone="America/New_York", ... ) shape: (3,) Series: '' [datetime[μs, America/New_York]] [ 2022-01-01 00:00:00 EST 2022-02-01 00:00:00 EST 2022-03-01 00:00:00 EST ]