Skip to content

Commit 62dbf4c

Browse files
committed
NANs for CAN:
* add missing columns
1 parent 3f6f456 commit 62dbf4c

File tree

1 file changed

+26
-0
lines changed
  • covid_act_now/delphi_covid_act_now

1 file changed

+26
-0
lines changed

covid_act_now/delphi_covid_act_now/run.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,38 @@
66
"""
77

88
import numpy as np
9+
import pandas as pd
910

1011
from delphi_utils import (
1112
create_export_csv,
1213
S3ArchiveDiffer,
14+
Nans
1315
)
1416

1517
from .constants import GEO_RESOLUTIONS, SIGNALS
1618
from .geo import geo_map
1719
from .pull import load_data, extract_testing_metrics
1820

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+
1941
def run_module(params):
2042
"""
2143
Run the CAN testing metrics indicator.
@@ -56,9 +78,12 @@ def run_module(params):
5678
# Perform geo aggregations and export to receiving
5779
for geo_res in GEO_RESOLUTIONS:
5880
print(f"Processing {geo_res}")
81+
# breakpoint()
5982
df = geo_map(df_county_testing, geo_res)
83+
df = add_missing_current_day(df)
6084

6185
# Export 'pcr_specimen_positivity_rate'
86+
df = add_nancodes(df, "pcr_tests_positive")
6287
exported_csv_dates = create_export_csv(
6388
df,
6489
export_dir=export_dir,
@@ -69,6 +94,7 @@ def run_module(params):
6994
df["val"] = df["sample_size"]
7095
df["sample_size"] = np.nan
7196
df["se"] = np.nan
97+
df = add_nancodes(df, "pcr_tests_total")
7298
exported_csv_dates = create_export_csv(
7399
df,
74100
export_dir=export_dir,

0 commit comments

Comments
 (0)