arundo/adtk

ValueError: Time series must have a monotonic time index.

Closed this issue · 5 comments

Code is as follows:

from adtk.transformer import ClassicSeasonalDecomposition
s_transformed = ClassicSeasonalDecomposition().fit_transform(s).rename("Seasonal decomposition residual")
plot(pd.concat([s, s_transformed], axis=1), ts_markersize=1);

my data frame has multiple numeric ( float & int columns with date as index ).

and I am getting following error:

ValueError Traceback (most recent call last)
in
1 from adtk.transformer import ClassicSeasonalDecomposition
----> 2 s_transformed = ClassicSeasonalDecomposition().fit_transform(s).rename("Seasonal decomposition residual")
3 plot(pd.concat([s, s_transformed], axis=1), ts_markersize=1);

~/jbooks/notebooks/lib/python3.6/site-packages/adtk/_transformer_base.py in fit_predict(self, ts)
94
95 """
---> 96 self.fit(ts)
97 return self.predict(ts)
98

~/jbooks/notebooks/lib/python3.6/site-packages/adtk/_transformer_base.py in fit(self, ts)
47
48 """
---> 49 self._fit(ts)
50
51 def predict(

~/jbooks/notebooks/lib/python3.6/site-packages/adtk/_base.py in _fit(self, ts)
172 # fit model for each column
173 for col in df.columns:
--> 174 self._models[col].fit(df[col])
175 self._fitted = 2
176 else:

~/jbooks/notebooks/lib/python3.6/site-packages/adtk/_transformer_base.py in fit(self, ts)
47
48 """
---> 49 self._fit(ts)
50
51 def predict(

~/jbooks/notebooks/lib/python3.6/site-packages/adtk/_base.py in _fit(self, ts)
152 if isinstance(ts, pd.Series):
153 s = ts.copy() # type: pd.Series
--> 154 self._fit_core(s)
155 self._fitted = 1
156 elif isinstance(ts, pd.DataFrame):

~/jbooks/notebooks/lib/python3.6/site-packages/adtk/transformer/_transformer_1d.py in _fit_core(self, s)
684 s.index.is_monotonic_increasing or s.index.is_monotonic_decreasing
685 ):
--> 686 raise ValueError("Time series must have a monotonic time index. ")
687 # remove starting and ending nans
688 s = s.loc[s.first_valid_index() : s[::-1].first_valid_index()].copy()

ValueError: Time series must have a monotonic time index.

Any help is highly appreciated...

For your input s, what does s.index.is_monotonic give you?

I am getting false for s.index.is_monotonic.. not sure.. what am I missing... for details review below screen capture...

image

That means the Series index is not monotonic. You need to make sure your Series index is DatetimeIndex and it is monotonic. adtk.data.validate_series may be helpful to you.

Thank you for your inputs.. my date column has duplicate as it's without timestamp... I mean without hours or minutes or seconds...

As per business requirements that is a valid scenario... also anomaly detection is on monthly transaction basis so I am confused how to proceed... Any help is highly appreciated

@tailaiw, thank you very much for guidance.. .I just created a new Data-frame with group-by on dates & started analyzing... appreciate your timely response... so taking a small break helped..