Preprocessing API¶
The pyrox.preprocessing subpackage holds the only pandas-touching code in pyrox. Layers, models, and inference runners stay pandas-free; this module is the bridge between user-supplied DataFrames and the JAX-only pyrox.nn layers.
SpatiotemporalFit¶
pyrox.preprocessing.SpatiotemporalFit
¶
Bases: Module
Immutable bundle of fitted feature layers + time-encoding scalars.
Replaces bayesnf's mutable SpatiotemporalDataHandler with a pure
PyTree so the whole bundle is JIT-friendly and picklable.
Attributes:
| Name | Type | Description |
|---|---|---|
standardize_layer |
Standardization
|
:class: |
fourier_layer |
FourierFeatures
|
:class: |
seasonal_layer |
SeasonalFeatures
|
:class: |
interaction_layer |
InteractionFeatures
|
:class: |
time_min |
float
|
Minimum time value across the training set, used as
an offset by :func: |
time_scale |
float
|
Multiplicative factor applied to |
feature_cols |
tuple[str, ...]
|
Names of the columns the standardization/feature layers expect, in order. |
target_col |
str
|
Name of the target column. |
Source code in src/pyrox/preprocessing/_pandas.py
fit_spatiotemporal¶
pyrox.preprocessing.fit_spatiotemporal(df, *, feature_cols, target_col, timetype='int', freq=None, seasonality_periods=(), num_seasonal_harmonics=(), fourier_degrees=(), interactions=(), standardize=None, time_col=0)
¶
Build a complete :class:SpatiotemporalFit from a DataFrame.
The training-side workflow is::
fit = fit_spatiotemporal(df, feature_cols=..., target_col=...)
and the predict-side workflow re-uses the same fit to encode
new data — concretely, by calling :func:encode_time_column with
the stored time_min and applying the layers stored on the
bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Training DataFrame. |
required |
feature_cols
|
Sequence[str]
|
Names of the input columns, in order. The first
column ( |
required |
target_col
|
str
|
Name of the target column. |
required |
timetype
|
Literal['int', 'datetime']
|
|
'int'
|
freq
|
str | None
|
Optional unit string for |
None
|
seasonality_periods
|
Sequence[float]
|
Periods (in time-unit) for seasonal features. Empty ⇒ no seasonal features. |
()
|
num_seasonal_harmonics
|
Sequence[int]
|
Harmonics per period; same length as
|
()
|
fourier_degrees
|
Sequence[int]
|
Per-input dyadic Fourier degrees. Length must
match |
()
|
interactions
|
Sequence[tuple[int, int]]
|
Pairs of input-column indices for interaction features. Empty ⇒ no interactions. |
()
|
standardize
|
Sequence[str] | None
|
Optional subset of feature columns to standardize.
|
None
|
time_col
|
int
|
Index of the time column inside |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
Fitted |
SpatiotemporalFit
|
class: |
Source code in src/pyrox/preprocessing/_pandas.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
fit_standardization¶
pyrox.preprocessing.fit_standardization(df, columns, *, eps=1e-12)
¶
Build a :class:Standardization layer from per-column mean / std.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Source DataFrame. |
required |
columns
|
Sequence[str]
|
Columns to standardize, in the order they will appear
in the array passed to :meth: |
required |
eps
|
float
|
Floor for the standard deviation; protects against division by zero on constant columns. |
1e-12
|
Returns:
| Type | Description |
|---|---|
Standardization
|
class: |
Source code in src/pyrox/preprocessing/_pandas.py
encode_time_column¶
pyrox.preprocessing.encode_time_column(series, *, timetype='int', freq=None, time_min=None)
¶
Convert a pandas time column into a unit-scale JAX float array.
For timetype="int", the series is cast directly to float32
and offset by its minimum (or by time_min if supplied).
For timetype="datetime", the series is converted to integer
nanoseconds, offset by its minimum, and divided by a unit factor
derived from freq ("D" ⇒ days, "H" ⇒ hours, "W" ⇒
weeks). When freq is None, the unit is days.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
1D time column. |
required |
timetype
|
Literal['int', 'datetime']
|
|
'int'
|
freq
|
str | None
|
Optional unit string for the datetime path. |
None
|
time_min
|
float | None
|
Optional fixed offset (use the value from a previous
|
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, ' N']
|
|
float
|
used, and the multiplicative scale ( |
float
|
|
Source code in src/pyrox/preprocessing/_pandas.py
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 171 172 | |