Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] FallbackForecaster fails with ForecastByLevel when nan_predict_policy='raise' #6230

Open
ninedigits opened this issue Mar 28, 2024 · 0 comments
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting

Comments

@ninedigits
Copy link
Contributor

Describe the bug

When forecasting hierarchical time series, such as with ForecastByLevel, the following line may not function as intended and may result in a ValueError being raised.

    def _validate_y_pred(self, y_pred):
        if self.nan_predict_policy in ("warn", "raise"):
            has_nans = y_pred.isnull().any() # Error caused here when using ForecastByLevel

To Reproduce

def test_forecastbylevel_nan_predict():
    from sktime.utils._testing.hierarchical import _make_hierarchical
    from sktime.forecasting.compose import ForecastByLevel

    df = _make_hierarchical(
        hierarchy_levels=(2, 2, 10),
        max_timepoints=10,
        min_timepoints=10,
        same_cutoff=True,
        n_columns=1,
        all_positive=True,
        index_type="period",
        random_state=0,
        add_nan=False,
    )
    forecaster1 = DummyForecaster(raise_at=None, predict_nans=True)
    forecaster2 = NaiveForecaster()
    forecaster = ForecastByLevel(
        FallbackForecaster(
            [
                ("forecaster1_pred_nans", forecaster1),
                ("forecaster2_expected_", forecaster2),
            ],
            nan_predict_policy="raise",
        )
    )
    fh = [1, 2, 3]
    forecaster.fit(y=df, fh=fh)
    y_pred_actual = forecaster.predict()

    forecaster2.fit(y=df, fh=[1, 2, 3])
    y_pred_expected = forecaster2.predict()

    pd.testing.assert_frame_equal(y_pred_expected, y_pred_actual)

Expected behavior

Additional context

Versions

@ninedigits ninedigits added the bug Something isn't working label Mar 28, 2024
ninedigits added a commit to ninedigits/sktime that referenced this issue Mar 28, 2024
@fkiraly fkiraly added the module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting label Mar 28, 2024
fkiraly pushed a commit that referenced this issue Apr 11, 2024
…dict_policy='raise'` (#6231)

Fixes error that occurs when `FallbackForecaster` is combined with
`ForecastByLevel` and `nan_predict_policy='raise'`
#6230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting
Projects
None yet
Development

No branches or pull requests

2 participants