@@ -104,6 +104,14 @@ class TestGeoMapper:
104104 ),
105105 )
106106 )
107+ mega_data_3 = pd .DataFrame (
108+ {
109+ "fips" : [1123 , 1125 , 1126 , 1128 , 1129 , 18181 ],
110+ "timestamp" : [pd .Timestamp ("2018-01-01" )] * 6 ,
111+ "visits" : [4 , 1 , 2 , 5 , 10 , 100001 ],
112+ "count" : [2 , 1 , 5 , 7 , 3 , 10021 ],
113+ }
114+ )
107115 jhu_uid_data = pd .DataFrame (
108116 {
109117 "jhu_uid" : [
@@ -208,6 +216,27 @@ def test_megacounty(self, geomapper):
208216 new_data [["count" ]].sum () - self .mega_data [["count" ]].sum ()
209217 ).sum () < 1e-3
210218
219+ new_data = geomapper .fips_to_megacounty (self .mega_data_3 , 4 , 1 )
220+ expected_df = pd .DataFrame (
221+ {
222+ "megafips" : ["01000" , "01128" , "01129" , "18181" ],
223+ "timestamp" : [pd .Timestamp ("2018-01-01" )] * 4 ,
224+ "visits" : [7 , 5 , 10 , 100001 ],
225+ "count" : [8 , 7 , 3 , 10021 ],
226+ }
227+ )
228+ pd .testing .assert_frame_equal (new_data .set_index ("megafips" ).sort_index (axis = 1 ), expected_df .set_index ("megafips" ).sort_index (axis = 1 ))
229+ new_data = geomapper .fips_to_megacounty (self .mega_data_3 , 4 , 1 , thr_col = "count" )
230+ expected_df = pd .DataFrame (
231+ {
232+ "megafips" : ["01000" , "01126" , "01128" , "18181" ],
233+ "timestamp" : [pd .Timestamp ("2018-01-01" )] * 4 ,
234+ "visits" : [15 , 2 , 5 , 100001 ],
235+ "count" : [6 , 5 , 7 , 10021 ],
236+ }
237+ )
238+ pd .testing .assert_frame_equal (new_data .set_index ("megafips" ).sort_index (axis = 1 ), expected_df .set_index ("megafips" ).sort_index (axis = 1 ))
239+
211240 def test_add_population_column (self , geomapper ):
212241 new_data = geomapper .add_population_column (self .fips_data_3 , "fips" )
213242 assert new_data .shape == (5 , 5 )
0 commit comments