9
9
from typing import Dict , Any
10
10
11
11
import numpy as np
12
- from delphi_utils import S3ArchiveDiffer , get_structured_logger , create_export_csv
12
+ from delphi_utils import S3ArchiveDiffer , get_structured_logger , create_export_csv , Nans
13
13
14
14
from .archive_diffs import arch_diffs
15
15
from .constants import (METRICS , SENSOR_NAME_MAP ,
16
16
SENSORS , INCIDENCE_BASE , GEO_RES )
17
17
from .pull import pull_nchs_mortality_data
18
18
19
19
20
+ def add_nancodes (df ):
21
+ """Add nancodes to the dataframe."""
22
+ # Default missingness codes
23
+ df ["missing_val" ] = Nans .NOT_MISSING
24
+ df ["missing_se" ] = Nans .NOT_APPLICABLE
25
+ df ["missing_sample_size" ] = Nans .NOT_APPLICABLE
26
+
27
+ # Mark any remaining nans with unknown
28
+ remaining_nans_mask = df ["val" ].isnull ()
29
+ df .loc [remaining_nans_mask , "missing_val" ] = Nans .OTHER
30
+ return df
31
+
20
32
def run_module (params : Dict [str , Any ]):
21
33
"""Run module for processing NCHS mortality data.
22
34
@@ -67,7 +79,8 @@ def run_module(params: Dict[str, Any]):
67
79
df ["val" ] = df [metric ]
68
80
df ["se" ] = np .nan
69
81
df ["sample_size" ] = np .nan
70
- df = df [~ df ["val" ].isnull ()]
82
+ df = add_nancodes (df )
83
+ # df = df[~df["val"].isnull()]
71
84
sensor_name = "_" .join ([SENSOR_NAME_MAP [metric ]])
72
85
dates = create_export_csv (
73
86
df ,
@@ -91,7 +104,8 @@ def run_module(params: Dict[str, Any]):
91
104
df ["val" ] = df [metric ] / df ["population" ] * INCIDENCE_BASE
92
105
df ["se" ] = np .nan
93
106
df ["sample_size" ] = np .nan
94
- df = df [~ df ["val" ].isnull ()]
107
+ df = add_nancodes (df )
108
+ # df = df[~df["val"].isnull()]
95
109
sensor_name = "_" .join ([SENSOR_NAME_MAP [metric ], sensor ])
96
110
dates = create_export_csv (
97
111
df ,
0 commit comments