Check cross-learning filters to specified panel group.
Validates that when groups=[group_name] is specified, predictions are
generated only for that panel group (all columns with that prefix).
Parameters
| Name |
Type |
Description |
Default |
forecaster
|
BaseForecaster
|
|
required
|
y_panel
|
DataFrame
|
|
required
|
Raises
| Type |
Description |
AssertionError
|
If filtered prediction doesn't match specified group
|
Source Code
View on GitHub
Source code in src/yohou/testing/panel.py
| def check_panel_single_group(forecaster, y_panel: pl.DataFrame) -> None:
"""Check cross-learning filters to specified panel group.
Validates that when groups=[group_name] is specified, predictions are
generated only for that panel group (all columns with that prefix).
Parameters
----------
forecaster : BaseForecaster
Fitted forecaster with panel data
y_panel : pl.DataFrame
Panel data with panel columns for testing
Raises
------
AssertionError
If filtered prediction doesn't match specified group
"""
_, y_panel_groups = inspect_panel(y_panel)
if len(y_panel_groups) > 0:
# Get first group prefix
first_group = list(y_panel_groups.keys())[0]
# Predict with specific group
y_pred = _call_predict(forecaster, forecasting_horizon=3, panel_group=first_group)
# Should have columns from the specified group (flat columns with __ separator)
group_cols = y_panel_groups[first_group]
assert len(group_cols) > 0, f"Group '{first_group}' should have columns"
for col in group_cols:
assert _column_present(col, y_pred.columns), (
f"Column '{col}' (or interval bounds) from group '{first_group}' "
f"should be in predictions. Got: {y_pred.columns}"
)
# Columns from any other group must be absent: filtering to one group
# means predictions are generated only for that group.
for other_group, other_cols in y_panel_groups.items():
if other_group == first_group:
continue
for col in other_cols:
assert not _column_present(col, y_pred.columns), (
f"Column '{col}' (or interval bounds) from group '{other_group}' "
f"should NOT be in predictions filtered to group '{first_group}'. Got: {y_pred.columns}"
)
|