6
6
"""
7
7
8
8
import numpy as np
9
+ import pandas as pd
9
10
10
11
from delphi_utils import (
11
12
create_export_csv ,
12
13
S3ArchiveDiffer ,
14
+ Nans
13
15
)
14
16
15
17
from .constants import GEO_RESOLUTIONS , SIGNALS
16
18
from .geo import geo_map
17
19
from .pull import load_data , extract_testing_metrics
18
20
21
+ def add_nancodes (df , signal ):
22
+ """Add nancodes to the dataframe."""
23
+ # Default missingness codes
24
+ df ["missing_val" ] = Nans .NOT_MISSING
25
+ df ["missing_se" ] = Nans .NOT_MISSING if signal == "pcr_tests_positive" else Nans .NOT_APPLICABLE
26
+ df ["missing_sample_size" ] = (
27
+ Nans .NOT_MISSING if signal == "pcr_tests_positive" else Nans .NOT_APPLICABLE
28
+ )
29
+
30
+ # Mark any nans with unknown
31
+ val_nans_mask = df ["val" ].isnull ()
32
+ df .loc [val_nans_mask , "missing_val" ] = Nans .UNKNOWN
33
+ if signal == "pcr_tests_positive" :
34
+ se_nans_mask = df ["se" ].isnull ()
35
+ df .loc [se_nans_mask , "missing_se" ] = Nans .UNKNOWN
36
+ sample_size_nans_mask = df ["sample_size" ].isnull ()
37
+ df .loc [sample_size_nans_mask , "missing_sample_size" ] = Nans .UNKNOWN
38
+
39
+ return df
40
+
19
41
def run_module (params ):
20
42
"""
21
43
Run the CAN testing metrics indicator.
@@ -56,9 +78,12 @@ def run_module(params):
56
78
# Perform geo aggregations and export to receiving
57
79
for geo_res in GEO_RESOLUTIONS :
58
80
print (f"Processing { geo_res } " )
81
+ # breakpoint()
59
82
df = geo_map (df_county_testing , geo_res )
83
+ df = add_missing_current_day (df )
60
84
61
85
# Export 'pcr_specimen_positivity_rate'
86
+ df = add_nancodes (df , "pcr_tests_positive" )
62
87
exported_csv_dates = create_export_csv (
63
88
df ,
64
89
export_dir = export_dir ,
@@ -69,6 +94,7 @@ def run_module(params):
69
94
df ["val" ] = df ["sample_size" ]
70
95
df ["sample_size" ] = np .nan
71
96
df ["se" ] = np .nan
97
+ df = add_nancodes (df , "pcr_tests_total" )
72
98
exported_csv_dates = create_export_csv (
73
99
df ,
74
100
export_dir = export_dir ,
0 commit comments