Example #1
0
class TestSplits:
    @given(t=period_indexes(min_length=1, max_length=1))
    @example(t=pd.PeriodIndex(["1974-12-31"], freq="W"))
    @example(t=pd.PeriodIndex(["1972-01-01"], freq="W"))
    @settings(deadline=None)
    def test_week_of_year(self, t):
        period = t[0]
        week = _week_of_year(period)
        assert re.match(r"\d{4}_\d\d?$", week)

    @given(
        df=giotto_time_series(min_length=3, max_length=500),
        cycle=st.one_of(
            st.sampled_from(["year", "quarter", "month", "week"]),
            st.from_regex(r"[1-9][DWMQY]", fullmatch=True),
        ),
    )
    @settings(deadline=None)
    def test__get_cycle_names_size(self, df, cycle):
        cycle = _get_cycle_names(df, cycle)
        assert len(cycle) == len(df)

    @given(
        df=giotto_time_series(min_length=3, max_length=500),
        cycle=st.one_of(
            st.sampled_from(["year", "quarter", "month", "week"]),
            st.from_regex(r"[1-9][DWMQY]", fullmatch=True),
        ),
        freq=st.from_regex(r"[1-9]?[DWMQ]", fullmatch=True),
    )
    @settings(deadline=None)
    def test__get_season_names_size(self, df, cycle, freq):
        seasons = _get_season_names(df, cycle, freq)
        assert len(seasons) == len(df)

    @given(
        df=giotto_time_series(min_length=3, max_length=500),
        cycle=st.one_of(
            st.sampled_from(["year", "quarter", "month", "week"]),
            st.from_regex(r"[1-9][DWMQY]", fullmatch=True),
        ),
        freq=st.one_of(st.from_regex(r"[1-9]?[DWMQ]", fullmatch=True), st.none()),
        agg=st.sampled_from(["mean", "sum", "last"]),
    )
    @settings(deadline=None)
    def test_seasonal_split_shape_named(self, df, cycle, freq, agg):
        split = seasonal_split(df, cycle=cycle, freq=freq, agg=agg)
        if freq is None:
            freq = df.index.freqstr
        assert split.stack().shape == df.resample(freq).agg(agg).dropna().shape
Example #2
0
class TestPeriodIndex:
    @given(period_indexes())
    def test_period_indexes_is_period(self, index):
        assert isinstance(index, pd.PeriodIndex)

    @given(period_indexes(min_length=10, max_length=1000))
    def test_period_indexes_size(self, index):
        assert 10 <= len(index) <= 1000

    @given(period_indexes(min_length=10, max_length=10))
    def test_period_indexes_size_fixed_value(self, index):
        assert len(index) == 10

    @given(period_indexes(min_length=0, max_length=0))
    def test_period_indexes_size_fixed_value_0(self, index):
        assert len(index) == 0

    @given(period_indexes())
    def test_period_indexes_boundaries(self, index):
        start_datetime = pd.Period("1979-12-31").to_timestamp()
        end_datetime = pd.Period("2020-01-01").to_timestamp()
        if len(index):
            assert index[0].to_timestamp() >= start_datetime
            assert index[-1].to_timestamp() <= end_datetime
Example #3
0
def n_time_series_with_same_index(
    draw, min_length: int = 5, min_n: int = 1, max_n: int = 5,
):
    n = draw(st.integers(min_value=min_n, max_value=max_n))
    index = draw(period_indexes(min_length=min_length))
    dictionary = {}
    for i in range(n):
        key = str(i)
        df_values = draw(
            arrays(
                dtype=np.float64,
                shape=index.shape[0],
                elements=st.floats(allow_nan=False, allow_infinity=False, width=32),
            )
        )
        value = pd.DataFrame(index=index, data=df_values)
        dictionary[key] = value
    return dictionary