def test_range_error(): idx = pd.Index([0, 1, 1, 2, 3, 5, 8, 13]) dp = DeterministicProcess( idx, constant=True, order=2, seasonal=True, period=2 ) with pytest.raises(TypeError, match="The index in the deterministic"): dp.range(0, 12)
def test_determintic_term_equiv(index): base = DeterministicProcess(pd.RangeIndex(0, 200), constant=True, order=2) dp = DeterministicProcess(index, constant=True, order=2) np.testing.assert_array_equal(base.in_sample(), dp.in_sample()) np.testing.assert_array_equal(base.out_of_sample(37), dp.out_of_sample(37)) np.testing.assert_array_equal(base.range(200, 237), dp.range(200, 237)) np.testing.assert_array_equal(base.range(50, 150), dp.range(50, 150)) np.testing.assert_array_equal(base.range(50, 250), dp.range(50, 250))
def test_range_casting(): idx = np.arange(120) dp = DeterministicProcess( idx, constant=True, order=1, seasonal=True, period=12 ) idx = pd.RangeIndex(0, 120) dp2 = DeterministicProcess( idx, constant=True, order=1, seasonal=True, period=12 ) pd.testing.assert_frame_equal(dp.in_sample(), dp2.in_sample()) pd.testing.assert_frame_equal(dp.range(100, 150), dp2.range(100, 150))
det_proc.out_of_sample(15) # `range(start, stop)` can also be used to produce the deterministic terms # over any range including in- and out-of-sample. # # ### Notes # # * When the index is a pandas `DatetimeIndex` or a `PeriodIndex`, then # `start` and `stop` can be date-like (strings, e.g., "2020-06-01", or # Timestamp) or integers. # * `stop` is always included in the range. While this is not very # Pythonic, it is needed since both statsmodels and Pandas include `stop` # when working with date-like slices. det_proc.range(190, 210) # ## Using a Date-like Index # # Next, we show the same steps using a `PeriodIndex`. index = pd.period_range("2020-03-01", freq="M", periods=60) det_proc = DeterministicProcess(index, constant=True, fourier=2) det_proc.in_sample().head(12) det_proc.out_of_sample(12) # `range` accepts date-like arguments, which are usually given as strings. det_proc.range("2025-01", "2026-01")
def test_non_unit_range(): idx = pd.RangeIndex(0, 700, 7) dp = DeterministicProcess(idx, constant=True) with pytest.raises(ValueError, match="The step of the index is not 1"): dp.range(11, 900)
def test_range_index_basic(): idx = pd.date_range("2000-1-1", freq="M", periods=120) dp = DeterministicProcess(idx, constant=True, order=1, seasonal=True) dp.range("2001-1-1", "2008-1-1") dp.range("2001-1-1", "2015-1-1") dp.range("2013-1-1", "2008-1-1") dp.range(0, 100) dp.range(100, 150) dp.range(130, 150) with pytest.raises(ValueError): dp.range("1990-1-1", "2010-1-1") idx = pd.period_range("2000-1-1", freq="M", periods=120) dp = DeterministicProcess(idx, constant=True, order=1, seasonal=True) dp.range("2001-1-1", "2008-1-1") dp.range("2001-1-1", "2015-1-1") dp.range("2013-1-1", "2008-1-1") with pytest.raises(ValueError, match="start must be non-negative"): dp.range(-7, 200) dp.range(0, 100) dp.range(100, 150) dp.range(130, 150) idx = pd.RangeIndex(0, 120) dp = DeterministicProcess(idx, constant=True, order=1, seasonal=True, period=12) dp.range(0, 100) dp.range(100, 150) dp.range(120, 150) dp.range(130, 150) with pytest.raises(ValueError): dp.range(-10, 0)