polars datetime-ranges for dataframe
Create a column of datetime ranges.
This command requires a plugin
The polars datetime-ranges command resides in the polars plugin. To use this command, you must install and register nu_plugin_polars. See the Plugins chapter in the book for more information.
Command Type
plugin
Signature
> polars datetime-ranges {flags}
Flags
--start, -s {any}: Start of the datetime range expression. This supports a string, date, or datetime expression.--end, -e {any}: End of the datetime range expression. This supports a string, date, or datetime expression.--interval, -i {any}: Interval of the datetime range expression. This supports a string or duration expression.--closed, -c {string}: Closed window of the datetime range expression. This supports 'left', 'right', 'both', or 'none'.--time-unit {string}: Time unit for the output datetime. One of: ns, us, ms.--time-zone {string}: Time zone for the output datetime. E.g. 'UTC', 'America/New_York'.--eager: Eagerly collect the datetime range expression into a dataframe.
Input/output types:
| input | output |
|---|---|
| any | polars_expression |
| any | polars_dataframe |
Examples
Eagerly create a column of per-row datetime ranges from a start, end, and interval
> polars datetime-ranges --start 2022-01-01 --end 2022-01-05 --interval 1d --eager
╭───┬─────────────────────────────╮
│ # │ literal │
├───┼─────────────────────────────┤
│ 0 │ ╭───┬─────────────────────╮ │
│ │ │ 0 │ 1640995200000000000 │ │
│ │ │ 1 │ 1641081600000000000 │ │
│ │ │ 2 │ 1641168000000000000 │ │
│ │ │ 3 │ 1641254400000000000 │ │
│ │ │ 4 │ 1641340800000000000 │ │
│ │ ╰───┴─────────────────────╯ │
╰───┴─────────────────────────────╯Create a column of per-row datetime ranges from start and end date columns
> [[start end]; [2022-01-01 2022-01-03] [2022-01-02 2022-01-03]]
| polars into-df
| polars select (polars datetime-ranges --start (polars col start) --end (polars col end) --interval 1d | polars as date_range)
╭───┬─────────────────────────────╮
│ # │ date_range │
├───┼─────────────────────────────┤
│ 0 │ ╭───┬─────────────────────╮ │
│ │ │ 0 │ 1640995200000000000 │ │
│ │ │ 1 │ 1641081600000000000 │ │
│ │ │ 2 │ 1641168000000000000 │ │
│ │ ╰───┴─────────────────────╯ │
│ 1 │ ╭───┬─────────────────────╮ │
│ │ │ 0 │ 1641081600000000000 │ │
│ │ │ 1 │ 1641168000000000000 │ │
│ │ ╰───┴─────────────────────╯ │
╰───┴─────────────────────────────╯