Esempio n. 1
0
def test_and_dict_of_lists():
    """
    Test AndAggregator with input as a dict of lists of time stamps or time
    stamp 2-tuples
    """
    lists = {
        "A": [
            (Timestamp("2017-1-1"), Timestamp("2017-1-2")),
            (Timestamp("2017-1-5"), Timestamp("2017-1-8")),
            Timestamp("2017-1-10"),
        ],
        "B": [
            Timestamp("2017-1-2"),
            (Timestamp("2017-1-3"), Timestamp("2017-1-6")),
            Timestamp("2017-1-8"),
            (Timestamp("2017-1-7"), Timestamp("2017-1-9")),
            (Timestamp("2017-1-11"), Timestamp("2017-1-11")),
        ],
    }
    assert aggt.AndAggregator().aggregate(lists) == [
        Timestamp("2017-1-2"),
        (Timestamp("2017-01-05 00:00:00"), Timestamp("2017-01-06 00:00:00")),
        (Timestamp("2017-1-7 00:00:00"), Timestamp("2017-1-8 00:00:00")),
    ]

    lists = {
        "A": [
            (Timestamp("2017-1-1"), Timestamp("2017-1-2")),
            (Timestamp("2017-1-5"), Timestamp("2017-1-8")),
            Timestamp("2017-1-10"),
        ],
        "B": [],
    }
    assert aggt.AndAggregator().aggregate(lists) == []
Esempio n. 2
0
def test_and_df():
    """
    Test AndAggregator with input as a DataFrame
    """
    df = pd.DataFrame(
        [[1, 1], [1, 0], [0, 1], [0, 0], [float("nan"), 1], [0, float("nan")]],
        index=pd.date_range(start="2017-1-1", periods=6, freq="D"),
    )
    pd.testing.assert_series_equal(
        aggt.AndAggregator().aggregate(df),
        pd.Series(
            [1, 0, 0, 0, float("nan"), 0],
            index=pd.date_range(start="2017-1-1", periods=6, freq="D"),
        ),
    )
Esempio n. 3
0
def test_detector_return_intermediate():
    s = pd.Series(
        [0, 1, 2, 3, 2, 1] * 10,
        index=pd.date_range(start="2017-1-1", periods=60, freq="D"),
    )
    my_pipe = Pipenet([
        {
            "name": "deseasonal_residual",
            "model": (transformer.NaiveSeasonalDecomposition(freq=6)),
            "input": "original",
        },
        {
            "name": "abs_residual",
            "model": transformer.CustomizedTransformer1D(transform_func=abs),
            "input": "deseasonal_residual",
        },
        {
            "name": "iqr_ad",
            "model": detector.InterQuartileRangeAD(c=(None, 3)),
            "input": "abs_residual",
        },
        {
            "name": "sign_check",
            "model": detector.ThresholdAD(high=0.0, low=-float("inf")),
            "input": "deseasonal_residual",
        },
        {
            "name": "and",
            "model": aggregator.AndAggregator(),
            "input": ["iqr_ad", "sign_check"],
        },
    ])
    result = my_pipe.fit_detect(s, return_intermediate=True)
    assert set(result.keys()) == {
        "original",
        "deseasonal_residual",
        "abs_residual",
        "iqr_ad",
        "sign_check",
        "and",
    }
Esempio n. 4
0
def test_skip_fit():
    s = pd.Series(
        [0, 1, 2, 3, 2, 1] * 10,
        index=pd.date_range(start="2017-1-1", periods=60, freq="D"),
    )

    deseasonal_residual = transformer.NaiveSeasonalDecomposition(freq=6)

    my_pipe = Pipenet([
        {
            "name": "deseasonal_residual",
            "model": deseasonal_residual,
            "input": "original",
        },
        {
            "name": "abs_residual",
            "model": transformer.CustomizedTransformer1D(transform_func=abs),
            "input": "deseasonal_residual",
        },
        {
            "name": "iqr_ad",
            "model": detector.InterQuartileRangeAD(c=(None, 3)),
            "input": "abs_residual",
        },
        {
            "name": "sign_check",
            "model": detector.ThresholdAD(high=0.0, low=-float("inf")),
            "input": "deseasonal_residual",
        },
        {
            "name": "and",
            "model": aggregator.AndAggregator(),
            "input": ["iqr_ad", "sign_check"],
        },
    ])
    with pytest.raises(RuntimeError):
        my_pipe.fit_detect(s, skip_fit=["deseasonal_residual"])
    my_pipe.fit_detect(s)