11
11
from delphi_utils import (
12
12
add_prefix ,
13
13
create_export_csv ,
14
- get_structured_logger
14
+ get_structured_logger ,
15
+ Nans
15
16
)
16
17
17
18
from .constants import (END_FROM_TODAY_MINUS ,
@@ -32,6 +33,22 @@ def log_exit(start_time, logger):
32
33
logger .info ("Completed indicator run" ,
33
34
elapsed_time_in_seconds = elapsed_time_in_seconds )
34
35
36
+ def add_nancodes (df ):
37
+ """Add nancodes to the dataframe."""
38
+ # Default missingness codes
39
+ df ["missing_val" ] = Nans .NOT_MISSING
40
+ df ["missing_se" ] = Nans .NOT_MISSING
41
+ df ["missing_sample_size" ] = Nans .NOT_MISSING
42
+
43
+ # Mark any remaining nans with unknown
44
+ remaining_nans_mask = df ["val" ].isnull ()
45
+ df .loc [remaining_nans_mask , "missing_val" ] = Nans .UNKNOWN
46
+ remaining_nans_mask = df ["se" ].isnull ()
47
+ df .loc [remaining_nans_mask , "missing_se" ] = Nans .UNKNOWN
48
+ remaining_nans_mask = df ["sample_size" ].isnull ()
49
+ df .loc [remaining_nans_mask , "missing_sample_size" ] = Nans .UNKNOWN
50
+ return df
51
+
35
52
def run_module (params : Dict [str , Any ]):
36
53
"""Run the quidel_covidtest indicator.
37
54
@@ -103,6 +120,7 @@ def run_module(params: Dict[str, Any]):
103
120
state_groups , smooth = smoothers [sensor ][1 ],
104
121
device = smoothers [sensor ][0 ], first_date = first_date ,
105
122
last_date = last_date )
123
+ state_df = add_nancodes (state_df )
106
124
create_export_csv (state_df , geo_res = "state" , sensor = sensor , export_dir = export_dir ,
107
125
start_date = export_start_date , end_date = export_end_date )
108
126
@@ -115,6 +133,7 @@ def run_module(params: Dict[str, Any]):
115
133
state_groups , geo_data , res_key , smooth = smoothers [sensor ][1 ],
116
134
device = smoothers [sensor ][0 ], first_date = first_date ,
117
135
last_date = last_date )
136
+ res_df = add_nancodes (res_df )
118
137
create_export_csv (res_df , geo_res = geo_res , sensor = sensor , export_dir = export_dir ,
119
138
start_date = export_start_date , end_date = export_end_date ,
120
139
remove_null_samples = True )
0 commit comments