Skip to content

Commit 05be4e4

Browse files
committed
Nans nchs
1 parent 3e2d5d4 commit 05be4e4

File tree

1 file changed

+17
-3
lines changed
  • nchs_mortality/delphi_nchs_mortality

1 file changed

+17
-3
lines changed

nchs_mortality/delphi_nchs_mortality/run.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Dict, Any
1010

1111
import numpy as np
12-
from delphi_utils import S3ArchiveDiffer, get_structured_logger
12+
from delphi_utils import S3ArchiveDiffer, get_structured_logger, Nans
1313

1414
from .archive_diffs import arch_diffs
1515
from .constants import (METRICS, SENSOR_NAME_MAP,
@@ -18,6 +18,18 @@
1818
from .pull import pull_nchs_mortality_data
1919

2020

21+
def add_nancodes(df):
22+
"""Add nancodes to the dataframe."""
23+
# Default missingness codes
24+
df["missing_val"] = Nans.NOT_MISSING
25+
df["missing_se"] = Nans.NOT_APPLICABLE
26+
df["missing_sample_size"] = Nans.NOT_APPLICABLE
27+
28+
# Mark any remaining nans with unknown
29+
remaining_nans_mask = df["val"].isnull()
30+
df.loc[remaining_nans_mask, "missing_val"] = Nans.UNKNOWN
31+
return df
32+
2133
def run_module(params: Dict[str, Any]):
2234
"""Run module for processing NCHS mortality data.
2335
@@ -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
export_csv(
7386
df,
@@ -86,7 +99,8 @@ def run_module(params: Dict[str, Any]):
8699
df["val"] = df[metric] / df["population"] * INCIDENCE_BASE
87100
df["se"] = np.nan
88101
df["sample_size"] = np.nan
89-
df = df[~df["val"].isnull()]
102+
df = add_nancodes(df)
103+
# df = df[~df["val"].isnull()]
90104
sensor_name = "_".join([SENSOR_NAME_MAP[metric], sensor])
91105
export_csv(
92106
df,

0 commit comments

Comments
 (0)