Skip to content

Commit 8ad5128

Browse files
committed
Enforce and test filenaming
1 parent 3a208b0 commit 8ad5128

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

changehc/delphi_changehc/load_data.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def load_denom_data(denom_filepath, dropdate, base_geo):
2525
"""
2626
assert base_geo == "fips", "base unit must be 'fips'"
2727

28+
denom_suffix = denom_filepath.split("/")[-1].split(".")[0][9:]
29+
assert denom_suffix == "All_Outpatients_By_County"
30+
denom_filetype = denom_filepath.split("/")[-1].split(".")[1]
31+
assert denom_filetype == "dat"
32+
2833
denom_data = pd.read_csv(
2934
denom_filepath,
3035
sep="|",
@@ -71,6 +76,11 @@ def load_covid_data(covid_filepath, dropdate, base_geo):
7176
"""
7277
assert base_geo == "fips", "base unit must be 'fips'"
7378

79+
covid_suffix = covid_filepath.split("/")[-1].split(".")[0][9:]
80+
assert covid_suffix == "Covid_Outpatients_By_County"
81+
covid_filetype = covid_filepath.split("/")[-1].split(".")[1]
82+
assert covid_filetype == "dat"
83+
7484
covid_data = pd.read_csv(
7585
covid_filepath,
7686
sep="|",

changehc/delphi_changehc/run.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ def run_module():
3030
# Denominator: "YYYYMMDD_All_Outpatients_By_County.dat.gz"
3131
# Numerator: "YYYYMMDD_Covid_Outpatients_By_County.dat.gz"
3232

33-
denom_suffix = params["input_denom_file"].split("/")[-1].split(".")[0][9:]
34-
assert denom_suffix == "All_Outpatients_By_County"
35-
covid_suffix = params["input_covid_file"].split("/")[-1].split(".")[0][9:]
36-
assert covid_suffix == "Covid_Outpatients_By_County"
37-
38-
denom_filetype = params["input_denom_file"].split("/")[-1].split(".")[1]
39-
assert denom_filetype == "dat"
40-
covid_filetype = params["input_covid_file"].split("/")[-1].split(".")[1]
41-
assert covid_filetype == "dat"
42-
4333
if params["drop_date"] is None:
4434
dropdate_denom = datetime.strptime(
4535
Path(params["input_denom_file"]).name.split("_")[0], "%Y%m%d"

changehc/tests/test_load_data.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@ def test_base_unit(self):
2727
with pytest.raises(AssertionError):
2828
load_denom_data(DENOM_FILEPATH, DROP_DATE, "foo")
2929

30+
with pytest.raises(AssertionError):
31+
load_denom_data("test_data/20200101_foo.dat", DROP_DATE, "fips")
32+
3033
with pytest.raises(AssertionError):
3134
load_covid_data(COVID_FILEPATH, DROP_DATE, "foo")
3235

36+
with pytest.raises(AssertionError):
37+
load_covid_data("test_data/20200101_foo.dat", DROP_DATE, "fips")
38+
3339
with pytest.raises(AssertionError):
3440
load_combined_data(DENOM_FILEPATH, COVID_FILEPATH, DROP_DATE, "foo")
3541

0 commit comments

Comments
 (0)