@@ -194,7 +194,13 @@ def predict(self, X: Union[TimeSeriesDataset, DataFrame], **kwargs):
194194
195195 elif isinstance (X , TimeSeriesDataset ):
196196 data = X
197- X = data .test_data [[self .time_col ] + X .regressors ]
197+ # By default we predict on the dataset's test partition.
198+ # Some internal call paths (e.g., training-metric logging) may pass a
199+ # dataset whose test partition is empty; fall back to train partition.
200+ if data .test_data is not None and len (data .test_data ):
201+ X = data .test_data [data .regressors + [data .time_col ]]
202+ else :
203+ X = data .train_data [data .regressors + [data .time_col ]]
198204
199205 if self ._model is not None :
200206 forecast = self ._model .predict (X , ** kwargs )
@@ -301,7 +307,13 @@ def predict(self, X, **kwargs):
301307
302308 if isinstance (X , TimeSeriesDataset ):
303309 data = X
304- X = data .test_data [data .regressors + [data .time_col ]]
310+ # By default we predict on the dataset's test partition.
311+ # Some internal call paths (e.g., training-metric logging) may pass a
312+ # dataset whose test partition is empty; fall back to train partition.
313+ if data .test_data is not None and len (data .test_data ):
314+ X = data .test_data [data .regressors + [data .time_col ]]
315+ else :
316+ X = data .train_data [data .regressors + [data .time_col ]]
305317
306318 X = X .rename (columns = {self .time_col : "ds" })
307319 if self ._model is not None :
@@ -327,11 +339,19 @@ def predict(self, X, **kwargs) -> pd.Series:
327339
328340 if isinstance (X , TimeSeriesDataset ):
329341 data = X
330- X = data .test_data [data .regressors + [data .time_col ]]
342+ # By default we predict on the dataset's test partition.
343+ # Some internal call paths (e.g., training-metric logging) may pass a
344+ # dataset whose test partition is empty; fall back to train partition.
345+ if data .test_data is not None and len (data .test_data ):
346+ X = data .test_data [data .regressors + [data .time_col ]]
347+ else :
348+ X = data .train_data [data .regressors + [data .time_col ]]
331349 else :
332350 X = X [self .regressors + [self .time_col ]]
333351
334352 if isinstance (X , DataFrame ):
353+ if X .shape [0 ] == 0 :
354+ return pd .Series ([], name = self .target_names [0 ], dtype = float )
335355 start = X [self .time_col ].iloc [0 ]
336356 end = X [self .time_col ].iloc [- 1 ]
337357 if len (self .regressors ):
@@ -829,6 +849,13 @@ def predict(self, X, **kwargs):
829849 if isinstance (X , TimeSeriesDataset ):
830850 data = X
831851 X = data .test_data
852+ # By default we predict on the dataset's test partition.
853+ # Some internal call paths (e.g., training-metric logging) may pass a
854+ # dataset whose test partition is empty; fall back to train partition.
855+ if data .test_data is not None and len (data .test_data ):
856+ X = data .test_data
857+ else :
858+ X = data .train_data
832859
833860 if self ._model is not None :
834861 X = X [self .regressors ]
0 commit comments