@@ -170,6 +170,36 @@ def test_neural_forecast_val_monitor_invalid():
170170 )
171171
172172
173+ # test that fit raises ValueError when series are too short for input_size + h
174+ def test_fit_raises_on_short_series ():
175+ # 10 timestamps, h=12, input_size=24 → train_size=10 < 24
176+ series = generate_series (n_series = 2 , min_length = 10 , max_length = 10 , equal_ends = True )
177+ model = NHITS (h = 12 , input_size = 24 , max_steps = 2 )
178+ nf = NeuralForecast (models = [model ], freq = "D" )
179+ with pytest .raises (ValueError , match = "requires at least" ):
180+ nf .fit (series )
181+
182+
183+ # test that fit passes when start_padding_enabled=True relaxes the constraint
184+ def test_fit_short_series_with_start_padding ():
185+ # 10 timestamps, h=12, input_size=24 but padding enabled → only needs 1 timestamp
186+ series = generate_series (n_series = 2 , min_length = 10 , max_length = 10 , equal_ends = True )
187+ model = NHITS (h = 12 , input_size = 24 , max_steps = 2 , start_padding_enabled = True )
188+ nf = NeuralForecast (models = [model ], freq = "D" )
189+ nf .fit (series ) # should not raise
190+
191+
192+ # test that cross_validation raises ValueError when series are too short (refit=True
193+ # calls fit() per window, which validates the training slice length)
194+ def test_cross_validation_raises_on_short_series ():
195+ # 30 timestamps, h=12, n_windows=1 → train slice=18 timestamps < input_size=24
196+ series = generate_series (n_series = 2 , min_length = 30 , max_length = 30 , equal_ends = True )
197+ model = NHITS (h = 12 , input_size = 24 , max_steps = 2 )
198+ nf = NeuralForecast (models = [model ], freq = "D" )
199+ with pytest .raises (ValueError , match = "requires at least" ):
200+ nf .cross_validation (series , n_windows = 1 , refit = True )
201+
202+
173203# test fit+cross_validation behaviour
174204def test_neural_forecast_fit_cross_validation (setup_airplane_data ):
175205 AirPassengersPanel_train , _ = setup_airplane_data
0 commit comments