Skip to content

[Backfill corrections] Align daily and rollup file formats; make dates portable #1760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions changehc/delphi_changehc/backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def store_backfill_file(df, _end_date, backfill_dir, numtype, geo, weekday):
'num', 'den']
backfilldata = backfilldata.loc[backfilldata["time_value"] >= _start_date,
selected_columns]

backfilldata["lag"] = [(_end_date - x).days for x in backfilldata["time_value"]]
backfilldata["time_value"] = backfilldata.time_value.dt.strftime("%Y-%m-%d")
backfilldata["issue_date"] = datetime.strftime(_end_date, "%Y-%m-%d")

backfilldata = backfilldata.astype({
"time_value": "string",
"issue_date": "string",
"fips": "string",
"state_id": "string"
})

path = backfill_dir + \
"/changehc_%s_as_of_%s.parquet"%(numtype, datetime.strftime(_end_date, "%Y%m%d"))
# Store intermediate file into the backfill folder
Expand Down Expand Up @@ -109,9 +121,6 @@ def get_date(file_link):
pdList = []
for fn in new_files:
df = pd.read_parquet(fn, engine='pyarrow')
issue_date = get_date(fn)
df["issue_date"] = issue_date
df["lag"] = [(issue_date - x).days for x in df["time_value"]]
pdList.append(df)
merged_file = pd.concat(pdList).sort_values(["time_value", "fips"])
path = backfill_dir + "/changehc_%s_from_%s_to_%s.parquet"%(
Expand Down
7 changes: 2 additions & 5 deletions changehc/tests/test_backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
class TestBackfill:

def test_store_backfill_file(self):

fn = "changehc_covid_as_of_20200101.parquet"
dropdate = datetime(2020, 1, 1)
numtype = "covid"
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_store_backfill_file(self):
backfill_df = pd.read_parquet(backfill_dir + "/"+ fn, engine='pyarrow')

selected_columns = ['time_value', 'fips', 'state_id',
'num', 'den']
'num', 'den', 'lag', 'issue_date']
assert set(selected_columns) == set(backfill_df.columns)

os.remove(backfill_dir + "/" + fn)
Expand Down Expand Up @@ -114,9 +114,6 @@ def test_merge_backfill_file(self):
if "from" in file:
continue
df = pd.read_parquet(file, engine='pyarrow')
issue_date = datetime.strptime(file[-16:-8], "%Y%m%d")
df["issue_date"] = issue_date
df["lag"] = [(issue_date - x).days for x in df["time_value"]]
pdList.append(df)
os.remove(file)
new_files = glob.glob(backfill_dir + "/changehc_%s*.parquet"%numtype)
Expand Down
14 changes: 11 additions & 3 deletions quidel_covidtest/delphi_quidel_covidtest/backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def store_backfill_file(df, _end_date, backfill_dir):
'num_age_0_17', 'den_age_0_17']
backfilldata = backfilldata.loc[backfilldata["time_value"] >= _start_date,
selected_columns]
backfilldata["lag"] = [(_end_date - x).days for x in backfilldata["time_value"]]
backfilldata["time_value"] = backfilldata.time_value.dt.strftime("%Y-%m-%d")
backfilldata["issue_date"] = datetime.strftime(_end_date, "%Y-%m-%d")

backfilldata = backfilldata.astype({
"time_value": "string",
"issue_date": "string",
"fips": "string",
"state_id": "string"
})

path = backfill_dir + \
"/quidel_covidtest_as_of_%s.parquet"%datetime.strftime(_end_date, "%Y%m%d")
# Store intermediate file into the backfill folder
Expand Down Expand Up @@ -108,9 +119,6 @@ def get_date(file_link):
pdList = []
for fn in new_files:
df = pd.read_parquet(fn, engine='pyarrow')
issue_date = get_date(fn)
df["issue_date"] = issue_date
df["lag"] = [(issue_date - x).days for x in df["time_value"]]
pdList.append(df)
merged_file = pd.concat(pdList).sort_values(["time_value", "fips"])
path = backfill_dir + "/quidel_covidtest_from_%s_to_%s.parquet"%(
Expand Down
6 changes: 2 additions & 4 deletions quidel_covidtest/tests/test_backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def test_store_backfill_file(self):
'num_age_18_49', 'den_age_18_49',
'num_age_50_64', 'den_age_50_64',
'num_age_65plus', 'den_age_65plus',
'num_age_0_17', 'den_age_0_17']
'num_age_0_17', 'den_age_0_17',
'lag', 'issue_date']
assert set(selected_columns) == set(backfill_df.columns)

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