7
7
from delphi .epidata .common .covidcast_row import CovidcastRow , set_df_dtypes
8
8
from delphi .epidata .acquisition .covidcast .test_utils import (
9
9
CovidcastTestRow ,
10
- covidcast_rows_as_api_compatibility_row_df ,
11
- covidcast_rows_as_api_row_df ,
12
- covidcast_rows_from_args ,
13
- transpose_dict ,
10
+ covidcast_rows_as_api_compatibility_row_df ,
11
+ covidcast_rows_as_api_row_df ,
12
+ covidcast_rows_from_args ,
13
+ transpose_dict ,
14
14
)
15
15
from delphi .epidata .acquisition .covidcast .test_utils import MSA
16
16
17
17
# py3tester coverage target (equivalent to `import *`)
18
- __test_target__ = ' delphi.epidata.common.covidcast_row'
18
+ __test_target__ = " delphi.epidata.common.covidcast_row"
19
19
20
20
21
21
class TestCovidcastRows (unittest .TestCase ):
22
- expected_df = set_df_dtypes (DataFrame ({
23
- "source" : ["src" ] * 10 ,
24
- "signal" : ["sig_base" ] * 5 + ["sig_other" ] * 5 ,
25
- "time_type" : ["day" ] * 10 ,
26
- "geo_type" : ["msa" ] * 10 ,
27
- "time_value" : [2021_05_01 + i for i in range (5 )] * 2 ,
28
- "geo_value" : [MSA [0 ]] * 10 ,
29
- "value" : range (10 ),
30
- "stderr" : [10.0 ] * 10 ,
31
- "sample_size" : [10.0 ] * 10 ,
32
- "missing_value" : [Nans .NOT_MISSING ] * 10 ,
33
- "missing_stderr" : [Nans .NOT_MISSING ] * 10 ,
34
- "missing_sample_size" : [Nans .NOT_MISSING ] * 10 ,
35
- "issue" : [2021_05_01 + i for i in range (5 )] * 2 ,
36
- "lag" : [0 ] * 10 ,
37
- "direction" : [None ] * 10
38
- }), CovidcastRow ._pandas_dtypes )
39
-
40
- def test_transpose_dict (self ):
41
- assert transpose_dict (
22
+ expected_df = set_df_dtypes (
23
+ DataFrame (
42
24
{
43
- "a" : [2 , 4 , 6 ],
44
- "b" : [3 , 5 , 7 ],
45
- "c" : [10 , 20 , 30 ]
25
+ "source" : ["src" ] * 10 ,
26
+ "signal" : ["sig_base" ] * 5 + ["sig_other" ] * 5 ,
27
+ "time_type" : ["day" ] * 10 ,
28
+ "geo_type" : ["msa" ] * 10 ,
29
+ "time_value" : [2021_05_01 + i for i in range (5 )] * 2 ,
30
+ "geo_value" : [MSA [0 ]] * 10 ,
31
+ "value" : range (10 ),
32
+ "stderr" : [10.0 ] * 10 ,
33
+ "sample_size" : [10.0 ] * 10 ,
34
+ "missing_value" : [Nans .NOT_MISSING ] * 10 ,
35
+ "missing_stderr" : [Nans .NOT_MISSING ] * 10 ,
36
+ "missing_sample_size" : [Nans .NOT_MISSING ] * 10 ,
37
+ "issue" : [2021_05_01 + i for i in range (5 )] * 2 ,
38
+ "lag" : [0 ] * 10 ,
39
+ "direction" : [None ] * 10 ,
46
40
}
47
- ) == [
48
- {"a" : 2 , "b" : 3 , "c" : 10 },
49
- {"a" : 4 , "b" : 5 , "c" : 20 },
50
- {"a" : 6 , "b" : 7 , "c" : 30 }
51
- ]
41
+ ),
42
+ CovidcastRow ._pandas_dtypes ,
43
+ )
52
44
45
+ def test_transpose_dict (self ):
46
+ assert transpose_dict ({"a" : [2 , 4 , 6 ], "b" : [3 , 5 , 7 ], "c" : [10 , 20 , 30 ]}) == [
47
+ {"a" : 2 , "b" : 3 , "c" : 10 },
48
+ {"a" : 4 , "b" : 5 , "c" : 20 },
49
+ {"a" : 6 , "b" : 7 , "c" : 30 },
50
+ ]
53
51
54
52
def test_CovidcastRow (self ):
55
53
df = CovidcastTestRow .make_default_row (
@@ -70,13 +68,12 @@ def test_CovidcastRow(self):
70
68
expected_df = self .expected_df .iloc [0 :1 ][df .columns ]
71
69
assert_frame_equal (df , expected_df )
72
70
73
-
74
71
def test_covidcast_rows (self ):
75
72
covidcast_rows = covidcast_rows_from_args (
76
73
signal = ["sig_base" ] * 5 + ["sig_other" ] * 5 ,
77
74
time_value = [2021_05_01 + i for i in range (5 )] * 2 ,
78
75
value = list (range (10 )),
79
- sanitize_fields = True
76
+ sanitize_fields = True ,
80
77
)
81
78
df = covidcast_rows_as_api_row_df (covidcast_rows )
82
79
expected_df = self .expected_df
@@ -86,7 +83,7 @@ def test_covidcast_rows(self):
86
83
signal = ["sig_base" ] * 5 + ["sig_other" ] * 5 ,
87
84
time_value = [2021_05_01 + i for i in range (5 )] * 2 ,
88
85
value = list (range (10 )),
89
- sanitize_fields = True
86
+ sanitize_fields = True ,
90
87
)
91
88
df = covidcast_rows_as_api_compatibility_row_df (covidcast_rows )
92
89
expected_df = self .expected_df [df .columns ]
0 commit comments