Skip to content

Commit 3d02733

Browse files
Jingjing TangJingjing Tang
Jingjing Tang
authored and
Jingjing Tang
committed
add the case when there is no daily file stored
1 parent c84ea3f commit 3d02733

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

claims_hosp/delphi_claims_hosp/backfill.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def merge_backfill_file(backfill_dir, backfill_merge_day, today,
7979
considerations
8080
"""
8181
new_files = glob.glob(backfill_dir + "/claims_hosp_as_of_*")
82+
if len(new_files) == 0: # if no any daily file is stored
83+
return
8284

8385
def get_date(file_link):
8486
# Keep the function here consistent with the backfill path in

claims_hosp/tests/backfill/.gitignore

Whitespace-only changes.

claims_hosp/tests/test_backfill.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,20 @@ def test_merge_backfill_file(self):
4747

4848
today = datetime.today()
4949

50-
new_files = glob.glob(backfill_dir + "/claims_hosp*.parquet")
5150
fn = "claims_hosp_from_20200611_to_20200614.parquet"
5251
assert fn not in os.listdir(backfill_dir)
5352

53+
# Check when there is no daily file to merge.
54+
today = datetime(2020, 6, 14)
55+
merge_backfill_file(backfill_dir, today.weekday(), today,
56+
test_mode=True, check_nd=8)
57+
assert fn not in os.listdir(backfill_dir)
58+
59+
# Generate backfill daily files
60+
for d in range(11, 15):
61+
dropdate = datetime(2020, 6, d)
62+
store_backfill_file(DATA_FILEPATH, dropdate, backfill_dir)
63+
5464
# Check the when the merged file is not generated
5565
today = datetime(2020, 6, 14)
5666
merge_backfill_file(backfill_dir, today.weekday(), today,
@@ -63,13 +73,18 @@ def test_merge_backfill_file(self):
6373
assert fn in os.listdir(backfill_dir)
6474

6575
# Read daily file
76+
new_files = glob.glob(backfill_dir + "/claims_hosp*.parquet")
6677
pdList = []
6778
for file in new_files:
6879
df = pd.read_parquet(file, engine='pyarrow')
6980
issue_date = datetime.strptime(file[-16:-8], "%Y%m%d")
7081
df["issue_date"] = issue_date
7182
df["lag"] = [(issue_date - x).days for x in df["time_value"]]
7283
pdList.append(df)
84+
os.remove(file)
85+
new_files = glob.glob(backfill_dir + "/claims_hosp*.parquet")
86+
assert len(new_files) == 1
87+
7388
expected = pd.concat(pdList).sort_values(["time_value", "fips"])
7489

7590
# Read the merged file

0 commit comments

Comments
 (0)