55from itertools import product
66
77import pandas as pd
8+ import numpy as np
89
910from conftest import TEST_DIR
1011
@@ -64,7 +65,6 @@ def test_output_files_exist(self, run_as_module):
6465 nf = "_" .join ([date , geo , metric , smther , "search" ]) + ".csv"
6566 expected_files .append (nf )
6667
67- csv_dates = list (set ([datetime .strptime (f .split ('_' )[0 ], "%Y%m%d" ) for f in csv_files [smther ] if smther in f ]))
6868 assert set (csv_files [smther ]).issuperset (set (expected_files ))
6969
7070
@@ -74,3 +74,24 @@ def test_output_file_format(self):
7474 )
7575 assert (df .columns .values == [
7676 "geo_id" , "val" , "se" , "sample_size" ]).all ()
77+
78+ def test_output_files_smoothed (self ):
79+ dates = [str (x ) for x in range (20200804 , 20200811 )]
80+
81+ smoothed = pd .read_csv (
82+ join (f"{ TEST_DIR } /receiving" ,
83+ f"{ dates [- 1 ]} _state_s01_smoothed_search.csv" )
84+ )
85+
86+ raw = pd .concat ([
87+ pd .read_csv (
88+ join (f"{ TEST_DIR } /receiving" ,
89+ f"{ date } _state_s01_raw_search.csv" )
90+ ) for date in dates
91+ ])
92+
93+ raw = raw .groupby ('geo_id' )['val' ].sum ()/ 7.0
94+ df = pd .merge (smoothed , raw , on = 'geo_id' ,
95+ suffixes = ('_smoothed' , '_raw' ))
96+
97+ assert np .allclose (df ['val_smoothed' ].values , df ['val_raw' ].values )
0 commit comments