77from delphi .epidata .common .covidcast_row import CovidcastRow , set_df_dtypes
88from delphi .epidata .acquisition .covidcast .test_utils import (
99 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 ,
1414)
1515from delphi .epidata .acquisition .covidcast .test_utils import MSA
1616
1717# py3tester coverage target (equivalent to `import *`)
18- __test_target__ = ' delphi.epidata.common.covidcast_row'
18+ __test_target__ = " delphi.epidata.common.covidcast_row"
1919
2020
2121class 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 (
4224 {
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 ,
4640 }
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+ )
5244
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+ ]
5351
5452 def test_CovidcastRow (self ):
5553 df = CovidcastTestRow .make_default_row (
@@ -70,13 +68,12 @@ def test_CovidcastRow(self):
7068 expected_df = self .expected_df .iloc [0 :1 ][df .columns ]
7169 assert_frame_equal (df , expected_df )
7270
73-
7471 def test_covidcast_rows (self ):
7572 covidcast_rows = covidcast_rows_from_args (
7673 signal = ["sig_base" ] * 5 + ["sig_other" ] * 5 ,
7774 time_value = [2021_05_01 + i for i in range (5 )] * 2 ,
7875 value = list (range (10 )),
79- sanitize_fields = True
76+ sanitize_fields = True ,
8077 )
8178 df = covidcast_rows_as_api_row_df (covidcast_rows )
8279 expected_df = self .expected_df
@@ -86,7 +83,7 @@ def test_covidcast_rows(self):
8683 signal = ["sig_base" ] * 5 + ["sig_other" ] * 5 ,
8784 time_value = [2021_05_01 + i for i in range (5 )] * 2 ,
8885 value = list (range (10 )),
89- sanitize_fields = True
86+ sanitize_fields = True ,
9087 )
9188 df = covidcast_rows_as_api_compatibility_row_df (covidcast_rows )
9289 expected_df = self .expected_df [df .columns ]
0 commit comments