12
12
from delphi_utils import (
13
13
create_export_csv ,
14
14
get_structured_logger
15
+ S3ArchiveDiffer ,
16
+ Nans
15
17
)
16
18
17
19
from .constants import GEO_RESOLUTIONS , SIGNALS
18
20
from .geo import geo_map
19
21
from .pull import load_data , extract_testing_metrics
20
22
23
+ def add_nancodes (df , signal ):
24
+ """Add nancodes to the dataframe."""
25
+ # Default missingness codes
26
+ df ["missing_val" ] = Nans .NOT_MISSING
27
+ df ["missing_se" ] = Nans .NOT_MISSING if signal == "pcr_tests_positive" else Nans .NOT_APPLICABLE
28
+ df ["missing_sample_size" ] = (
29
+ Nans .NOT_MISSING if signal == "pcr_tests_positive" else Nans .NOT_APPLICABLE
30
+ )
31
+
32
+ # Mark any nans with unknown
33
+ val_nans_mask = df ["val" ].isnull ()
34
+ df .loc [val_nans_mask , "missing_val" ] = Nans .OTHER
35
+ if signal == "pcr_tests_positive" :
36
+ se_nans_mask = df ["se" ].isnull ()
37
+ df .loc [se_nans_mask , "missing_se" ] = Nans .OTHER
38
+ sample_size_nans_mask = df ["sample_size" ].isnull ()
39
+ df .loc [sample_size_nans_mask , "missing_sample_size" ] = Nans .OTHER
40
+
41
+ return df
42
+
21
43
def run_module (params ):
22
44
"""
23
45
Run the CAN testing metrics indicator.
@@ -59,6 +81,7 @@ def run_module(params):
59
81
df = geo_map (df_county_testing , geo_res )
60
82
61
83
# Export 'pcr_specimen_positivity_rate'
84
+ df = add_nancodes (df , "pcr_tests_positive" )
62
85
exported_csv_dates = create_export_csv (
63
86
df ,
64
87
export_dir = export_dir ,
@@ -69,6 +92,7 @@ def run_module(params):
69
92
df ["val" ] = df ["sample_size" ]
70
93
df ["sample_size" ] = np .nan
71
94
df ["se" ] = np .nan
95
+ df = add_nancodes (df , "pcr_tests_total" )
72
96
exported_csv_dates = create_export_csv (
73
97
df ,
74
98
export_dir = export_dir ,
0 commit comments