JoaquinAmatRodrigo / skforecast

Time series forecasting with machine learning models
https://skforecast.org
BSD 3-Clause "New" or "Revised" License
1.09k stars 125 forks source link

syntax error !! #642

Closed MahmoudAdel-hub closed 4 months ago

MahmoudAdel-hub commented 7 months ago

UnboundLocalError Traceback (most recent call last) Input In [71], in <cell line: 1>() ----> 1 mc1.predict(steps=10 ,exog=X)

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\skforecast\ForecasterAutoregDirect\ForecasterAutoregDirect.py:778, in ForecasterAutoregDirect.predict(self, steps, last_window, exog) 775 if last_window is None: 776 last_window = self.last_window --> 778 check_predict_input( 779 forecaster_name = type(self).name, 780 steps = steps, 781 fitted = self.fitted, 782 included_exog = self.included_exog, 783 index_type = self.index_type, 784 index_freq = self.index_freq, 785 window_size = self.window_size, 786 last_window = last_window, 787 last_window_exog = None, 788 exog = exog, 789 exog_type = self.exog_type, 790 exog_col_names = self.exog_col_names, 791 interval = None, 792 alpha = None, 793 max_steps = self.steps, 794 levels = None, 795 series_col_names = None 796 ) 798 last_window = last_window.iloc[-self.window_size:].copy() 800 if exog is not None:

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\skforecast\utils\utils.py:705, in check_predict_input(forecaster_name, steps, fitted, included_exog, index_type, index_freq, window_size, last_window, last_window_exog, exog, exog_type, exog_col_names, interval, alpha, max_steps, levels, series_col_names) 699 raise TypeError( 700 (f"Expected frequency of type {index_freq} for exog. " 701 f"Got {exog_index.freqstr}.") 702 ) 704 # Check exog starts one step ahead of last_window end. --> 705 expected_index = expand_index(last_window.index, 1)[0] 706 if expected_index != exog.index[0]: 707 raise ValueError( 708 (f"To make predictions exog must start one step ahead of last_window.\n" 709 f" last_window ends at : {last_window.index[-1]}.\n" 710 f" exog starts at : {exog.index[0]}.\n" 711 f" Expected index : {expected_index}.") 712 )

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\skforecast\utils\utils.py:1132, in expand_index(index, steps) 1126 else: 1127 new_index = pd.RangeIndex( 1128 start = 0, 1129 stop = steps 1130 ) -> 1132 return new_index

UnboundLocalError: local variable 'new_index' referenced before assignment

JavierEscobarOrtiz commented 7 months ago

Hello @MahmoudAdel-hub,

Thank you for opening the issue. Please could you share your code on how you got this error?

This issue is fixed in PR #633 for the next release, but need to identify how it appears.

Thank you very much.