Skip to content

Commit f3a2e33

Browse files
committed
move lag and issue_date setting to daily files in quidel_covidtest
1 parent ff9d515 commit f3a2e33

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

quidel_covidtest/delphi_quidel_covidtest/backfill.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ def store_backfill_file(df, _end_date, backfill_dir):
5656
'num_age_0_17', 'den_age_0_17']
5757
backfilldata = backfilldata.loc[backfilldata["time_value"] >= _start_date,
5858
selected_columns]
59+
backfilldata["lag"] = [(_end_date - x).days for x in backfilldata["time_value"]]
60+
backfilldata["time_value"] = backfilldata.time_value.dt.strftime("%Y-%m-%d")
61+
backfilldata["issue_date"] = datetime.strftime(_end_date, "%Y-%m-%d")
62+
63+
backfilldata = backfilldata.astype({
64+
"time_value": "string",
65+
"issue_date": "string",
66+
"fips": "string",
67+
"state_id": "string"
68+
})
69+
5970
path = backfill_dir + \
6071
"/quidel_covidtest_as_of_%s.parquet"%datetime.strftime(_end_date, "%Y%m%d")
6172
# Store intermediate file into the backfill folder
@@ -108,9 +119,6 @@ def get_date(file_link):
108119
pdList = []
109120
for fn in new_files:
110121
df = pd.read_parquet(fn, engine='pyarrow')
111-
issue_date = get_date(fn)
112-
df["issue_date"] = issue_date
113-
df["lag"] = [(issue_date - x).days for x in df["time_value"]]
114122
pdList.append(df)
115123
merged_file = pd.concat(pdList).sort_values(["time_value", "fips"])
116124
path = backfill_dir + "/quidel_covidtest_from_%s_to_%s.parquet"%(

quidel_covidtest/tests/test_backfill.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def test_store_backfill_file(self):
4949
'num_age_18_49', 'den_age_18_49',
5050
'num_age_50_64', 'den_age_50_64',
5151
'num_age_65plus', 'den_age_65plus',
52-
'num_age_0_17', 'den_age_0_17']
52+
'num_age_0_17', 'den_age_0_17',
53+
'lag', 'issue_date']
5354
assert set(selected_columns) == set(backfill_df.columns)
5455

5556
os.remove(backfill_dir + "/" + fn)
@@ -86,9 +87,6 @@ def test_merge_backfill_file(self):
8687
if "from" in file:
8788
continue
8889
df = pd.read_parquet(file, engine='pyarrow')
89-
issue_date = datetime.strptime(file[-16:-8], "%Y%m%d")
90-
df["issue_date"] = issue_date
91-
df["lag"] = [(issue_date - x).days for x in df["time_value"]]
9290
pdList.append(df)
9391
os.remove(file)
9492
new_files = glob.glob(backfill_dir + "/quidel_covidtest*.parquet")

0 commit comments

Comments
 (0)