-
Notifications
You must be signed in to change notification settings - Fork 141
/
test_aggregators.py
132 lines (120 loc) · 4.14 KB
/
test_aggregators.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from pandas import Timestamp
import pandas as pd
import adtk.aggregator as aggt
def test_or_dict_of_lists():
"""
Test OrAggregator 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.OrAggregator().aggregate(lists) == [
(Timestamp("2017-01-01 00:00:00"), Timestamp("2017-01-02 00:00:00")),
(Timestamp("2017-01-03 00:00:00"), Timestamp("2017-01-09 00:00:00")),
Timestamp("2017-1-10"),
Timestamp("2017-1-11"),
]
def test_or_df():
"""
Test OrAggregator 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.OrAggregator().aggregate(df),
pd.Series(
[1, 1, 1, 0, 1, float("nan")],
index=pd.date_range(start="2017-1-1", periods=6, freq="D"),
),
)
def test_or_dict_of_dfs():
"""
Test OrAggregator with input as a dict of DataFrame
"""
df1 = 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"),
)
df2 = 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.OrAggregator().aggregate({"A": df1, "B": df2}),
pd.Series(
[1, 1, 1, 0, 1, float("nan")],
index=pd.date_range(start="2017-1-1", periods=6, freq="D"),
),
)
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")),
]
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"),
),
)
def test_and_dict_of_dfs():
"""
Test AndAggregator with input as a dict of DataFrame
"""
df1 = 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"),
)
df2 = 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({"A": df1, "B": df2}),
pd.Series(
[1, 0, 0, 0, float("nan"), 0],
index=pd.date_range(start="2017-1-1", periods=6, freq="D"),
),
)