10
10
from delphi_utils import (
11
11
create_export_csv ,
12
12
S3ArchiveDiffer ,
13
+ Nans
13
14
)
14
15
15
16
from .constants import GEO_RESOLUTIONS , SIGNALS
16
17
from .geo import geo_map
17
18
from .pull import load_data , extract_testing_metrics
18
19
20
+ def add_nancodes (df , signal ):
21
+ """Add nancodes to the dataframe."""
22
+ # Default missingness codes
23
+ df ["missing_val" ] = Nans .NOT_MISSING
24
+ df ["missing_se" ] = Nans .NOT_MISSING if signal == "pcr_tests_positive" else Nans .NOT_APPLICABLE
25
+ df ["missing_sample_size" ] = (
26
+ Nans .NOT_MISSING if signal == "pcr_tests_positive" else Nans .NOT_APPLICABLE
27
+ )
28
+
29
+ # Mark any nans with unknown
30
+ val_nans_mask = df ["val" ].isnull ()
31
+ df .loc [val_nans_mask , "missing_val" ] = Nans .UNKNOWN
32
+ if signal == "pcr_tests_positive" :
33
+ se_nans_mask = df ["se" ].isnull ()
34
+ df .loc [se_nans_mask , "missing_se" ] = Nans .UNKNOWN
35
+ sample_size_nans_mask = df ["sample_size" ].isnull ()
36
+ df .loc [sample_size_nans_mask , "missing_sample_size" ] = Nans .UNKNOWN
37
+
38
+ return df
39
+
19
40
def run_module (params ):
20
41
"""
21
42
Run the CAN testing metrics indicator.
@@ -56,9 +77,11 @@ def run_module(params):
56
77
# Perform geo aggregations and export to receiving
57
78
for geo_res in GEO_RESOLUTIONS :
58
79
print (f"Processing { geo_res } " )
80
+ # breakpoint()
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