Closed vpozdnyakov closed 3 years ago
TimeSeriesDataSet object is successfully created
I try to create a TimeSeriesDataSet object as described in README.md, but I get an error
TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`
Link to notebook: https://colab.research.google.com/drive/14rlslq0O1hVnQiW-tSV1lA6hX9iw0iBl?usp=sharing
!pip install pytorch-forecasting -q from pytorch_forecasting import TimeSeriesDataSet import pandas as pd aus_retail = pd.read_csv('https://raw.githubusercontent.com/vpozdnyakov/probabilistic_forecasting/main/datasets/aus_retail.csv', index_col=0) aus_retail.index = pd.to_datetime(aus_retail.index) data = [] for col in aus_retail.iloc[:, :4].columns: ts = aus_retail.loc[:, [col]] ts['ts_id'] = col ts = ts.rename(columns={col: 'value'}) data.append(ts) data = pd.concat(data) data.index.name = 'time_id' data = data.reset_index() training = TimeSeriesDataSet( data, time_idx='time_id', target='value', group_ids=['ts_id'], max_encoder_length=60, max_prediction_length=60)
Here is a traceback
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-37-8deed329ccbc> in <module>() 23 group_ids=['ts_id'], 24 max_encoder_length=60, ---> 25 max_prediction_length=60) 3 frames /usr/local/lib/python3.7/dist-packages/pytorch_forecasting/data/timeseries.py in __init__(self, data, time_idx, target, group_ids, weight, max_encoder_length, min_encoder_length, min_prediction_idx, min_prediction_length, max_prediction_length, static_categoricals, static_reals, time_varying_known_categoricals, time_varying_known_reals, time_varying_unknown_categoricals, time_varying_unknown_reals, variable_groups, dropout_categoricals, constant_fill_strategy, allow_missings, lags, add_relative_time_idx, add_target_scales, add_encoder_length, target_normalizer, categorical_encoders, scalers, randomize_length, predict_mode) 427 # filtering for min_prediction_idx will be done on subsequence level ensuring 428 # minimal decoder index is always >= min_prediction_idx --> 429 data = data[lambda x: x[self.time_idx] >= self.min_prediction_idx - self.max_encoder_length - self.max_lag] 430 data = data.sort_values(self.group_ids + [self.time_idx]) 431 /usr/local/lib/python3.7/dist-packages/pandas/core/frame.py in __getitem__(self, key) 2869 def __getitem__(self, key): 2870 key = lib.item_from_zerodim(key) -> 2871 key = com.apply_if_callable(key, self) 2872 2873 if is_hashable(key): /usr/local/lib/python3.7/dist-packages/pandas/core/common.py in apply_if_callable(maybe_callable, obj, **kwargs) 339 """ 340 if callable(maybe_callable): --> 341 return maybe_callable(obj, **kwargs) 342 343 return maybe_callable /usr/local/lib/python3.7/dist-packages/pytorch_forecasting/data/timeseries.py in <lambda>(x) 427 # filtering for min_prediction_idx will be done on subsequence level ensuring 428 # minimal decoder index is always >= min_prediction_idx --> 429 data = data[lambda x: x[self.time_idx] >= self.min_prediction_idx - self.max_encoder_length - self.max_lag] 430 data = data.sort_values(self.group_ids + [self.time_idx]) 431 pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps._Timestamp.__sub__() pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps._Timestamp.__add__() TypeError: Addition/subtraction of integers and integer-arrays with Timestamp is no longer supported. Instead of adding/subtracting `n`, use `n * obj.freq`
Sorry, I missed that the time_idx column should be integer
time_idx
Environment Details
Expected behavior
TimeSeriesDataSet object is successfully created
Actual behavior
I try to create a TimeSeriesDataSet object as described in README.md, but I get an error
Code to reproduce the problem
Link to notebook: https://colab.research.google.com/drive/14rlslq0O1hVnQiW-tSV1lA6hX9iw0iBl?usp=sharing
Here is a traceback