99from typing import Dict , Any
1010
1111import 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
1313
1414from .archive_diffs import arch_diffs
1515from .constants import (METRICS , SENSOR_NAME_MAP ,
1616 SENSORS , INCIDENCE_BASE , GEO_RES )
1717from .pull import pull_nchs_mortality_data
1818
1919
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+
2032def run_module (params : Dict [str , Any ]):
2133 """Run module for processing NCHS mortality data.
2234
@@ -67,7 +79,8 @@ def run_module(params: Dict[str, Any]):
6779 df ["val" ] = df [metric ]
6880 df ["se" ] = np .nan
6981 df ["sample_size" ] = np .nan
70- df = df [~ df ["val" ].isnull ()]
82+ df = add_nancodes (df )
83+ # df = df[~df["val"].isnull()]
7184 sensor_name = "_" .join ([SENSOR_NAME_MAP [metric ]])
7285 dates = create_export_csv (
7386 df ,
@@ -91,7 +104,8 @@ def run_module(params: Dict[str, Any]):
91104 df ["val" ] = df [metric ] / df ["population" ] * INCIDENCE_BASE
92105 df ["se" ] = np .nan
93106 df ["sample_size" ] = np .nan
94- df = df [~ df ["val" ].isnull ()]
107+ df = add_nancodes (df )
108+ # df = df[~df["val"].isnull()]
95109 sensor_name = "_" .join ([SENSOR_NAME_MAP [metric ], sensor ])
96110 dates = create_export_csv (
97111 df ,
0 commit comments