-
Notifications
You must be signed in to change notification settings - Fork 141
/
test_attribute.py
105 lines (102 loc) · 3.36 KB
/
test_attribute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Test read-only attributes"""
import pytest
import pandas as pd
import adtk.detector as detector
testCases = [
{
"model": detector.QuantileAD(),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": -float("inf"), "abs_high_": float("inf")},
},
{
"model": detector.QuantileAD(low=0.1),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": 1, "abs_high_": float("inf")},
},
{
"model": detector.QuantileAD(high=0.9),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": -float("inf"), "abs_high_": 9},
},
{
"model": detector.QuantileAD(low=0.1, high=0.9),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": 1, "abs_high_": 9},
},
{
"model": detector.InterQuartileRangeAD(),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": 2.5 - 15, "abs_high_": 7.5 + 15},
},
{
"model": detector.InterQuartileRangeAD(c=2),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": 2.5 - 10, "abs_high_": 7.5 + 10},
},
{
"model": detector.InterQuartileRangeAD(c=(2, 4)),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": 2.5 - 10, "abs_high_": 7.5 + 20},
},
{
"model": detector.InterQuartileRangeAD(c=(2, None)),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": 2.5 - 10, "abs_high_": float("inf")},
},
{
"model": detector.InterQuartileRangeAD(c=(None, 4)),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": -float("inf"), "abs_high_": 7.5 + 20},
},
{
"model": detector.InterQuartileRangeAD(c=None),
"s": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"a": {"abs_low_": -float("inf"), "abs_high_": float("inf")},
},
{
"model": detector.SeasonalAD(method="naive", freq=4),
"s": [0, 1, 2, 1] * 10,
"a": {"freq_": 4, "seasonal_": [0, 1, 2, 1]},
},
{
"model": detector.SeasonalAD(method="naive", freq=8),
"s": [0, 1, 2, 1] * 10,
"a": {"freq_": 8, "seasonal_": [0, 1, 2, 1, 0, 1, 2, 1]},
},
{
"model": detector.SeasonalAD(method="naive"),
"s": [0, 1, 2, 1] * 10,
"a": {"freq_": 4, "seasonal_": [0, 1, 2, 1]},
},
{
"model": detector.SeasonalAD(method="stl"),
"s": [0, 1, 2, 1] * 10,
"a": {"freq_": 4, "seasonal_": [-1, 0, 1, 0]},
},
{
"model": detector.SeasonalAD(method="stl", freq=8),
"s": [0, 1, 2, 1] * 10,
"a": {"freq_": 8, "seasonal_": [-1, 0, 1, 0, -1, 0, 1, 0]},
},
]
@pytest.mark.parametrize("testCase", testCases)
def test_attribute(testCase):
"""Test fit_detect the detector."""
s = pd.Series(
testCase["s"],
pd.date_range(start="2017-1-1", periods=len(testCase["s"]), freq="D"),
)
model = testCase["model"]
for key, value in testCase["a"].items():
with pytest.raises(AttributeError):
getattr(model, key)
model.fit(s)
for key, value in testCase["a"].items():
if isinstance(value, list):
pd.testing.assert_series_equal(
getattr(model, key),
pd.Series(value, index=s.index[: len(value)]),
check_dtype=False,
)
else:
assert getattr(model, key) == value