1- import pytest
2-
31from os .path import join
42
3+ import pytest
4+
55import numpy as np
66import pandas as pd
7- from delphi_usafacts .geo import fips_to_state , disburse , geo_map
7+ from delphi_usafacts .geo import disburse , geo_map
88
99MAP_DF = pd .read_csv (
1010 join (".." , "static" , "fips_prop_pop.csv" ),
1111 dtype = {"fips" : int }
1212)
1313
14- sensor = "new_counts"
15- class TestFipsToState :
16-
17- def test_normal (self ):
18-
19- assert fips_to_state ("53003" ) == "wa"
20- assert fips_to_state ("48027" ) == "tx"
21- assert fips_to_state ("12003" ) == "fl"
22- assert fips_to_state ("50103" ) == "vt"
23- assert fips_to_state ("15003" ) == "hi"
24-
14+ SENSOR = "new_counts"
2515
2616class TestDisburse :
17+ """Tests for the `geo.disburse()` function."""
2718 def test_even (self ):
28-
19+ """Tests that values are disbursed evenly across recipients."""
2920 df = pd .DataFrame (
3021 {
3122 "fips" : ["51093" , "51175" , "51620" ],
@@ -43,8 +34,9 @@ def test_even(self):
4334
4435
4536class TestGeoMap :
37+ """Tests for `geo.geo_map()`."""
4638 def test_incorrect_geo (self ):
47-
39+ """Tests that an invalid resolution raises an error."""
4840 df = pd .DataFrame (
4941 {
5042 "fips" : ["53003" , "48027" , "50103" ],
@@ -56,10 +48,10 @@ def test_incorrect_geo(self):
5648 )
5749
5850 with pytest .raises (ValueError ):
59- geo_map (df , "département" , MAP_DF , sensor )
51+ geo_map (df , "département" , MAP_DF , SENSOR )
6052
6153 def test_county (self ):
62-
54+ """Tests that values are correctly aggregated at the county level."""
6355 df = pd .DataFrame (
6456 {
6557 "fips" : ["53003" , "48027" , "50103" ],
@@ -70,7 +62,7 @@ def test_county(self):
7062 }
7163 )
7264
73- new_df = geo_map (df , "county" , MAP_DF , sensor )
65+ new_df = geo_map (df , "county" , MAP_DF , SENSOR )
7466
7567 exp_incidence = df ["new_counts" ] / df ["population" ] * 100000
7668 exp_cprop = df ["cumulative_counts" ] / df ["population" ] * 100000
@@ -81,7 +73,7 @@ def test_county(self):
8173 assert set (new_df ["cumulative_prop" ].values ) == set (exp_cprop .values )
8274
8375 def test_state (self ):
84-
76+ """Tests that values are correctly aggregated at the state level."""
8577 df = pd .DataFrame (
8678 {
8779 "fips" : ["04001" , "04003" , "04009" , "25023" ],
@@ -92,7 +84,7 @@ def test_state(self):
9284 }
9385 )
9486
95- new_df = geo_map (df , "state" , MAP_DF , sensor )
87+ new_df = geo_map (df , "state" , MAP_DF , SENSOR )
9688
9789 exp_incidence = np .array ([27 , 13 ]) / np .array ([2500 , 25 ]) * 100000
9890 exp_cprop = np .array ([165 , 60 ]) / np .array ([2500 , 25 ]) * 100000
@@ -106,7 +98,7 @@ def test_state(self):
10698 assert (new_df ["cumulative_prop" ].values == exp_cprop ).all ()
10799
108100 def test_hrr (self ):
109-
101+ """Tests that values are correctly aggregated at the HRR level."""
110102 df = pd .DataFrame (
111103 {
112104 "fips" : ["13009" , "13017" , "13021" , "09015" ],
@@ -117,7 +109,7 @@ def test_hrr(self):
117109 }
118110 )
119111
120- new_df = geo_map (df , "hrr" , MAP_DF , sensor )
112+ new_df = geo_map (df , "hrr" , MAP_DF , SENSOR )
121113
122114 exp_incidence = np .array ([13 , 27 ]) / np .array ([25 , 2500 ]) * 100000
123115 exp_cprop = np .array ([60 , 165 ]) / np .array ([25 , 2500 ]) * 100000
@@ -131,7 +123,7 @@ def test_hrr(self):
131123 assert new_df ["cumulative_prop" ].values == pytest .approx (exp_cprop )
132124
133125 def test_msa (self ):
134-
126+ """Tests that values are correctly aggregated at the MSA level."""
135127 df = pd .DataFrame (
136128 {
137129 "fips" : ["13009" , "13017" , "13021" , "09015" ],
@@ -142,7 +134,7 @@ def test_msa(self):
142134 }
143135 )
144136
145- new_df = geo_map (df , "msa" , MAP_DF , sensor )
137+ new_df = geo_map (df , "msa" , MAP_DF , SENSOR )
146138
147139 exp_incidence = np .array ([2 , 13 ]) / np .array ([300 , 25 ]) * 100000
148140 exp_cprop = np .array ([45 , 60 ]) / np .array ([300 , 25 ]) * 100000
0 commit comments