window_futures¶
yohou.utils.window_futures(X_future, observation_times, forecasting_horizon, interval, *, time_col='time')
¶
Window known-future features into step-indexed columns.
For each observation time T and forecast horizon H, extracts values at
T + 1*interval through T + H*interval from X_future, producing
step-indexed columns <col>_step_1 through <col>_step_H.
The output has one row per observation time and uses "time" as the
time column (set to the observation time).
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X_future
|
DataFrame
|
Known-future data with a |
required |
observation_times
|
Series
|
Series of observation timestamps to window from. |
required |
forecasting_horizon
|
int
|
Number of forward steps (H) to extract per observation time. |
required |
interval
|
str or timedelta
|
Time frequency between steps (e.g., |
required |
time_col
|
str
|
Name of the time column in |
"time"
|
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Wide DataFrame with |
Raises ¶
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If no value columns remain after removing |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> holidays = pl.DataFrame({
... "time": [
... datetime(2020, 1, 1),
... datetime(2020, 1, 2),
... datetime(2020, 1, 3),
... datetime(2020, 1, 4),
... datetime(2020, 1, 5),
... ],
... "is_holiday": [1, 0, 0, 1, 0],
... })
>>> obs_times = pl.Series([datetime(2020, 1, 1), datetime(2020, 1, 2)])
>>> window_futures(holidays, obs_times, forecasting_horizon=3, interval="1d")
shape: (2, 4)
┌─────────────────────┬───────────────────┬───────────────────┬───────────────────┐
│ time ┆ is_holiday_step_1 ┆ is_holiday_step_2 ┆ is_holiday_step_3 │
│ --- ┆ --- ┆ --- ┆ --- │
│ datetime[μs] ┆ i64 ┆ i64 ┆ i64 │
╞═════════════════════╪═══════════════════╪═══════════════════╪═══════════════════╡
│ 2020-01-01 00:00:00 ┆ 0 ┆ 0 ┆ 1 │
│ 2020-01-02 00:00:00 ┆ 0 ┆ 1 ┆ 0 │
└─────────────────────┴───────────────────┴───────────────────┴───────────────────┘
Source Code ¶
Source code in src/yohou/utils/pivot.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |