Skip to content

Commit 2baa587

Browse files
authored
Merge pull request #5 from nimish/hot-fix
2 parents 9fa1819 + 22e80d7 commit 2baa587

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/tsgam_estimator/tsgam_estimator.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,9 @@ def _fit_ar_model(self, X_array: ndarray, y: ndarray, time_indices: ndarray) ->
16881688
self.ar_noise_loc_ = None
16891689
self.ar_noise_scale_ = None
16901690

1691-
def predict(self, X: pd.DataFrame) -> ndarray:
1691+
def predict(self, X: pd.DataFrame,
1692+
remove_periodic : bool = False, remove_exogenous : bool = False,
1693+
remove_trend : bool = False) -> ndarray:
16921694
"""
16931695
Predict target values for new data.
16941696
@@ -1739,7 +1741,7 @@ def predict(self, X: pd.DataFrame) -> ndarray:
17391741
timestamps, X_array = self._ensure_timestamp_index(X)
17401742

17411743
# Prediction data must be regularly spaced with no gaps
1742-
self._validate_frequency(timestamps, self.freq_)
1744+
self._validate_frequency(timestamps, self.freq_, allow_gaps=True)
17431745

17441746
# Convert timestamps to indices using stored reference
17451747
time_indices = self._timestamps_to_indices(timestamps, self.time_reference_)
@@ -1754,7 +1756,7 @@ def predict(self, X: pd.DataFrame) -> ndarray:
17541756
predictions = np.full(len(X_array), constant_value)
17551757

17561758
# Add exogenous terms if present
1757-
if self.config.exog_config:
1759+
if self.config.exog_config and not remove_exogenous:
17581760
for ix, exog_cfg in enumerate(self.config.exog_config):
17591761
exog_var = X_array[:, ix]
17601762

@@ -1798,7 +1800,7 @@ def predict(self, X: pd.DataFrame) -> ndarray:
17981800
predictions += exog_pred
17991801

18001802
# Add Fourier terms if present
1801-
if self.config.multi_periodic_config:
1803+
if self.config.multi_periodic_config and not remove_periodic:
18021804
# Check for NaN in time_indices
18031805
if np.any(np.isnan(time_indices)):
18041806
raise ValueError("Time indices contain NaN. Check timestamp conversion.")
@@ -1866,7 +1868,8 @@ def predict(self, X: pd.DataFrame) -> ndarray:
18661868
predictions += fourier_contrib
18671869

18681870
# Add trend term if present
1869-
if self.config.trend_config is not None and self.config.trend_config.trend_type != TrendType.NONE and 'trend' in self.variables_:
1871+
if (self.config.trend_config is not None and self.config.trend_config.trend_type != TrendType.NONE
1872+
and 'trend' in self.variables_ and not remove_trend):
18701873
trend = self.variables_['trend'].value
18711874
if trend is None:
18721875
raise ValueError("Trend coefficients are None. Model may not have converged.")
@@ -1906,7 +1909,8 @@ def predict(self, X: pd.DataFrame) -> ndarray:
19061909
trend_extended[n_periods_fit:] = trend[-1]
19071910

19081911
trend = trend_extended
1909-
1912+
elif n_periods_pred < n_periods_fit:
1913+
trend = trend[:T_pred.shape[1]]
19101914
# Add trend term to predictions
19111915
predictions += T_pred @ trend
19121916

0 commit comments

Comments
 (0)