From 5b9a3f6ddf44396b4ea4c77cfda27883df7c36df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:52:21 +0000 Subject: [PATCH 1/3] Initial plan From f44ec6da1e2af0f83472beef9cffb02746d5ddec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:54:30 +0000 Subject: [PATCH 2/3] Apply code fixes: NameError, performance optimization, and code quality improvements Co-authored-by: bartzbeielstein <32470350+bartzbeielstein@users.noreply.github.com> --- .../processing/n2n_predict_with_covariates.py | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py b/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py index dffbcda13..fd5dc277d 100644 --- a/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py +++ b/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py @@ -278,17 +278,29 @@ def _get_day_night_features( extended_index = pd.date_range(start=start, end=cov_end, freq=freq, tz=timezone) - sunrise_hour = [ - sun(location.observer, date=date, tzinfo=location.timezone)["sunrise"] - for date in extended_index - ] - sunset_hour = [ - sun(location.observer, date=date, tzinfo=location.timezone)["sunset"] - for date in extended_index - ] + # Cache sunrise and sunset times per unique calendar date to avoid + # recomputing them for every timestamp in the extended_index. + normalized_dates = extended_index.normalize() + unique_dates = normalized_dates.unique() + + sunrise_map = {} + sunset_map = {} + for d in unique_dates: + s = sun(location.observer, date=d, tzinfo=location.timezone) + sunrise_map[d] = s["sunrise"] + sunset_map[d] = s["sunset"] + + sunrise_series = pd.Series( + [sunrise_map[d] for d in normalized_dates], + index=extended_index, + ) + sunset_series = pd.Series( + [sunset_map[d] for d in normalized_dates], + index=extended_index, + ) - sunrise_hour = pd.Series(sunrise_hour, index=extended_index).dt.round("h").dt.hour - sunset_hour = pd.Series(sunset_hour, index=extended_index).dt.round("h").dt.hour + sunrise_hour = sunrise_series.dt.round("h").dt.hour + sunset_hour = sunset_series.dt.round("h").dt.hour sun_light_features = pd.DataFrame( { @@ -444,7 +456,8 @@ def _create_interaction_features( transformer_poly = PolynomialFeatures( degree=degree, interaction_only=True, include_bias=False - ).set_output(transform="pandas") + ) + transformer_poly = transformer_poly.set_output(transform="pandas") weather_window_cols = [ col @@ -725,8 +738,7 @@ def n2n_predict_with_covariates( # Set default model_dir if not provided if model_dir is None: from spotforecast2_safe.data.fetch_data import get_cache_home - - model_dir = get_cache_home() / "forecasters" + model_dir = get_cache_home() / "forecasters" # Input Validation if forecast_horizon <= 0: @@ -888,9 +900,11 @@ def n2n_predict_with_covariates( axis=1, ) - assert ( - sum(exogenous_features.isnull().sum()) == 0 - ), "Missing values in exogenous features" + missing_count = int(exogenous_features.isnull().sum().sum()) + if missing_count != 0: + raise ValueError( + f"Missing values in exogenous features: {missing_count} missing entries" + ) # Apply cyclical encoding exogenous_features = _apply_cyclical_encoding( From 4bea9b7d7e85bcde00ca5d8b081c66f33bc03d1f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 19:56:46 +0000 Subject: [PATCH 3/3] Remove unnecessary int() conversion in missing_count calculation Co-authored-by: bartzbeielstein <32470350+bartzbeielstein@users.noreply.github.com> --- .../processing/n2n_predict_with_covariates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py b/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py index fd5dc277d..a575a031e 100644 --- a/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py +++ b/src/spotforecast2_safe/processing/n2n_predict_with_covariates.py @@ -900,7 +900,7 @@ def n2n_predict_with_covariates( axis=1, ) - missing_count = int(exogenous_features.isnull().sum().sum()) + missing_count = exogenous_features.isnull().sum().sum() if missing_count != 0: raise ValueError( f"Missing values in exogenous features: {missing_count} missing entries"