Closed KoustavDS closed 1 year ago
Hi @KoustavDS, add_holidays
expects a pd.DatetimeIndex, so you have to call it like this:
cov_holiday = holidays_timeseries(new_series1.time_index, country_code = 'US')
@dennisbader thank you. It is working now.
Describe the bug
I am trying to run a global model (NBEATS/TFT) with 50 time-series having 365 timestamp each.Can use the below code to create the data. I am trying to add covariates like day, month, holiday in a stacked format along with each series. But getting the below error while adding this line of code. _"cov_holiday = holidays_timeseries(new_series1,countrycode = 'US')"
Please note, I am not getting any error while adding day or month.
ERROR::----->
AttributeError Traceback (most recent call last) Cell In[40], line 13 11 cov_month = datetime_attribute_timeseries(new_series1, attribute="month") 12 cov_day = datetime_attribute_timeseries(new_series1, attribute="day") ---> 13 cov_holiday = holidays_timeseries(new_series1,country_code = 'US') 14 all_cov = cov_month.stack(cov_day) 15 all_cov = all_cov.stack(cov_holiday)
File /opt/conda/lib/python3.10/site-packages/darts/utils/timeseries_generation.py:574, in holidays_timeseries(time_index, country_code, prov, state, column_name, until, add_length, dtype) 540 """ 541 Creates a binary univariate TimeSeries with index
time_index
that equals 1 at every index that lies within 542 (or equals) a selected country's holiday, and 0 otherwise. (...) 570 A new binary holiday TimeSeries instance. 571 """ 573 time_index = _extend_time_index_until(time_index, until, add_length) --> 574 scope = range(time_index[0].year, (time_index[-1] + pd.Timedelta(days=1)).year) 575 country_holidays = holidays.country_holidays( 576 country_code, prov=prov, state=state, years=scope 577 ) 578 index_series = pd.Series(time_index, index=time_index)AttributeError: 'TimeSeries' object has no attribute 'year'
To Reproduce
new_arry = np.array(np.random.randint(1000,size=(365,20))) new_data = pd.DataFrame(new_arry) newdata.columns = ['col' + str(i) for i in new_data.columns] new_data['col_dt'] = pd.date_range(start='1/1/2022', periods=len(new_data), freq='D') new_data = new_data.set_index('col_dt')
all_ts = [] all_ts_cov = [] for i in new_data.columns.tolist(): ind_data = new_data[i] first_non_null_index = new_data[i].notna().idxmax() new_series = ind_data[first_non_null_index:] new_series1 = TimeSeries.from_series(new_series) cov_month = datetime_attribute_timeseries(new_series1, attribute="month") cov_day = datetime_attribute_timeseries(new_series1, attribute="day") cov_holiday = holidays_timeseries(new_series1,country_code = 'US') all_cov = cov_month.stack(cov_day) all_cov = all_cov.stack(cov_holiday) all_ts.append(new_series1) all_ts_cov.append(cov_month)
print(new_series1)
Expected behavior Expecting of creating a covariate series with day, month along with holiday(binary 1,0)
System (please complete the following information): python version : 3.10 Darts version : 0.25.0