def test_seasonal_from_index_err(): index = pd.Index([0, 1, 1, 2, 3, 5, 8, 12]) with pytest.raises(TypeError): Seasonality.from_index(index) index = pd.date_range("2000-1-1", periods=10)[[0, 1, 2, 3, 5, 8]] with pytest.raises(ValueError): Seasonality.from_index(index)
def test_seasonality_smoke(index, forecast_index): s = Seasonality(12) s.in_sample(index) steps = 83 if forecast_index is None else len(forecast_index) warn = None if ( is_int_index(index) and np.any(np.diff(index) != 1) or ( type(index) is pd.Index and max(index) > 2 ** 63 and forecast_index is None ) ): warn = UserWarning with pytest_warns(warn): s.out_of_sample(steps, index, forecast_index) assert isinstance(s.period, int) str(s) hash(s) if isinstance(index, (pd.DatetimeIndex, pd.PeriodIndex)) and index.freq: s = Seasonality.from_index(index) s.in_sample(index) s.out_of_sample(steps, index, forecast_index) Seasonality.from_index(list(index))
def test_seasonality_time_index(time_index): tt = Seasonality.from_index(time_index) assert tt.period == 5 fcast = tt.out_of_sample(steps=12, index=time_index) new_idx = DeterministicTerm._extend_index(time_index, 12) pd.testing.assert_index_equal(fcast.index, new_idx)