polars.time_ranges#

polars.time_ranges(
start: time | IntoExpr | None = None,
end: time | IntoExpr | None = None,
interval: str | timedelta = '1h',
*,
closed: ClosedInterval = 'both',
eager: Literal[False] = False,
) Expr[source]#
polars.time_ranges(
start: time | IntoExpr | None = None,
end: time | IntoExpr | None = None,
interval: str | timedelta = '1h',
*,
closed: ClosedInterval = 'both',
eager: Literal[True],
) Series
polars.time_ranges(
start: time | IntoExpr | None = None,
end: time | IntoExpr | None = None,
interval: str | timedelta = '1h',
*,
closed: ClosedInterval = 'both',
eager: bool,
) Series | Expr

Create a column of time ranges.

Parameters:
start

Lower bound of the time range. If omitted, defaults to time(0, 0, 0, 0).

end

Upper bound of the time range. If omitted, defaults to time(23, 59, 59, 999999).

interval

Interval of the range periods, specified as a Python timedelta object or a Polars duration string like 1h30m25s.

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.

Returns:
Expr or Series

Column of data type List(Time).

See also

time_range

Generate a single time range.

Examples

>>> from datetime import time
>>> df = pl.DataFrame(
...     {
...         "start": [time(9, 0), time(10, 0)],
...         "end": time(11, 0),
...     }
... )
>>> df.with_columns(pl.time_ranges("start", "end"))
shape: (2, 3)
┌──────────┬──────────┬────────────────────────────────┐
│ start    ┆ end      ┆ time_range                     │
│ ---      ┆ ---      ┆ ---                            │
│ time     ┆ time     ┆ list[time]                     │
╞══════════╪══════════╪════════════════════════════════╡
│ 09:00:00 ┆ 11:00:00 ┆ [09:00:00, 10:00:00, 11:00:00] │
│ 10:00:00 ┆ 11:00:00 ┆ [10:00:00, 11:00:00]           │
└──────────┴──────────┴────────────────────────────────┘