Skip to content

Commit 1851b32

Browse files
committed
NANs quidel covidtest:
* add missing columns
1 parent 3e2d5d4 commit 1851b32

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

changehc/delphi_changehc/update_sensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def update_sensor(self,
190190
# load data
191191
data.reset_index(inplace=True)
192192
data_frame = self.geo_reindex(data)
193+
breakpoint()
193194
# handle if we need to adjust by weekday
194195
wd_params = Weekday.get_params(data_frame) if self.weekday else None
195196
# run sensor fitting code (maybe in parallel)

quidel_covidtest/delphi_quidel_covidtest/run.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from delphi_utils import (
1212
add_prefix,
1313
create_export_csv,
14-
get_structured_logger
14+
get_structured_logger,
15+
Nans
1516
)
1617

1718
from .constants import (END_FROM_TODAY_MINUS, EXPORT_DAY_RANGE,
@@ -32,6 +33,22 @@ def log_exit(start_time, logger):
3233
logger.info("Completed indicator run",
3334
elapsed_time_in_seconds=elapsed_time_in_seconds)
3435

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+
3552
def run_module(params: Dict[str, Any]):
3653
"""Run the quidel_covidtest indicator.
3754
@@ -102,6 +119,7 @@ def run_module(params: Dict[str, Any]):
102119
state_groups, smooth=smoothers[sensor][1],
103120
device=smoothers[sensor][0], first_date=first_date,
104121
last_date=last_date)
122+
state_df = add_nancodes(state_df)
105123
create_export_csv(state_df, geo_res="state", sensor=sensor, export_dir=export_dir,
106124
start_date=export_start_date, end_date=export_end_date)
107125

@@ -114,6 +132,7 @@ def run_module(params: Dict[str, Any]):
114132
state_groups, geo_data, res_key, smooth=smoothers[sensor][1],
115133
device=smoothers[sensor][0], first_date=first_date,
116134
last_date=last_date)
135+
res_df = add_nancodes(res_df)
117136
create_export_csv(res_df, geo_res=geo_res, sensor=sensor, export_dir=export_dir,
118137
start_date=export_start_date, end_date=export_end_date,
119138
remove_null_samples=True)

quidel_covidtest/tests/test_run.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ def test_output_files(self, clean_receiving_dir):
6363
df = pd.read_csv(
6464
join("./receiving", "20200718_state_covid_ag_smoothed_pct_positive.csv")
6565
)
66-
assert (df.columns.values == ["geo_id", "val", "se", "sample_size"]).all()
66+
expected_columns = [
67+
"geo_id", "val", "se", "sample_size",
68+
"missing_val", "missing_se", "missing_sample_size"
69+
]
70+
assert (df.columns.values == expected_columns).all()
6771

6872
# test_intermediate_file
6973
flag = None

0 commit comments

Comments
 (0)