Skip to content

Commit 39c3fc0

Browse files
committed
Add more edge cases, fix incorrect time_values
1 parent 2563cd4 commit 39c3fc0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/acquisition/rvdss/pull_historic.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ def create_percent_positive_detection_table(table,modified_date,start_year, flu=
276276
table.columns=[re.sub("tests",virus+"_tests",c) for c in table.columns]
277277
table.columns =[re.sub(" ","_",col) for col in table.columns]
278278

279+
# make sure weeks 1-9 have leading 0 when creating epiweek
280+
table['week'] = pd.to_numeric(table['week'],downcast="integer")
281+
279282
table=table.rename(columns={'week':"epiweek"})
280283
table['epiweek'] = [get_report_date(week, start_year,epi=True) for week in table['epiweek']]
281284

@@ -322,10 +325,13 @@ def fix_edge_cases(table,season,caption,current_week):
322325
# In week 11 of the 2022-2023 season, in the positive hmpv table,
323326
# a date is written as 022-09-03, instead of 2022-09-03
324327
table.loc[table['week'] == 35, 'week end'] = "2022-09-03"
325-
elif season[0] == '2016' and current_week == 32 and "influenza" in caption.text.lower():
326-
# In week 11 of the 2022-2023 season, in the positive hmpv table,
327-
# a date is written as 022-09-03, instead of 2022-09-03
328-
table.loc[table['week'] == 32, 'week end'] = "2017-08-12"
328+
elif season[0] == '2016':
329+
if current_week == 32 and "influenza" in caption.text.lower():
330+
# In week 11 of the 2022-2023 season, in the positive hmpv table,
331+
# a date is written as 022-09-03, instead of 2022-09-03
332+
table.loc[table['week'] == 32, 'week end'] = "2017-08-12"
333+
if "detections" not in caption.text.lower():
334+
table.loc[table['week'] == 40, 'week end'] = "2016-10-08"
329335
elif season[0] == '2021' and "parainfluenza" in caption.text.lower():
330336
# In multiple weeks of the 2021-2022 season, in the positive hpiv table,
331337
# the date for week 12 is 2022-03-19, instead of 2022-03-26
@@ -338,6 +344,8 @@ def fix_edge_cases(table,season,caption,current_week):
338344
table.loc[table['week'] == 36, 'week end'] = "2013-09-07"
339345
elif current_week == 35:
340346
table.loc[table['week'] == 35, 'week end'] = "2013-08-31"
347+
elif current_week == 38:
348+
table.loc[table['week'] == 38, 'week end'] = "2013-09-21"
341349
return(table)
342350

343351
def fetch_one_season_from_report(url):

tests/acquisition/rvdss/test_pull_historic.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
pd.DataFrame([{"week":32,"week end":"2017-08-17"}]),
5050
pd.DataFrame([{"week":12,"week end":"2022-03-19"}]),
5151
pd.DataFrame([{"week":35,"week end":"2012-08-31"}]),
52-
pd.DataFrame({"week":[35,36],"week end":["2012-08-31","2012-09-07"]})]
52+
pd.DataFrame({"week":[35,36],"week end":["2012-08-31","2012-09-07"]}),
53+
pd.DataFrame([{"week":40,"week end":"2016-10-09"}]),
54+
pd.DataFrame([{"week":38,"week end":"2013-09-22"}])]
5355

5456
expected_edge_case_tables=[
5557
pd.DataFrame(columns=['week', 'week end', 'canada tests', 'entero/rhino%', 'at tests',
@@ -73,7 +75,9 @@
7375
pd.DataFrame([{"week":32,"week end":"2017-08-12"}]),
7476
pd.DataFrame([{"week":12,"week end":"2022-03-26"}]),
7577
pd.DataFrame([{"week":35,"week end":"2013-08-31"}]),
76-
pd.DataFrame({"week":[35,36],"week end":["2013-08-31","2013-09-07"]})]
78+
pd.DataFrame({"week":[35,36],"week end":["2013-08-31","2013-09-07"]}),
79+
pd.DataFrame([{"week":40,"week end":"2016-10-08"}]),
80+
pd.DataFrame([{"week":38,"week end":"2013-09-21"}])]
7781

7882
example_edge_case_captions=[
7983
[t for t in captions if "Entero" in t.text][0],
@@ -85,14 +89,16 @@
8589
[t for t in captions if "Influenza" in t.text][0],
8690
[t for t in captions if "Para" in t.text][0],
8791
[t for t in captions if "RSV" in t.text][0],
92+
[t for t in captions if "Influenza" in t.text][0],
93+
[t for t in captions if "Influenza" in t.text][0],
8894
[t for t in captions if "Influenza" in t.text][0]]
8995

9096
example_edge_case_seasons=[["2017","2018"],["2017","2018"],["2017","2018"],
9197
["2015","2016"],["2022","2023"],["2021","2022"],
9298
["2016","2017"],["2021","2022"], ["2013","2014"],
93-
["2013","2014"]]
99+
["2013","2014"],["2016","2017"],["2013","2014"]]
94100

95-
example_edge_case_weeks=[35,35,47,41,11,10,32,14,35,36]
101+
example_edge_case_weeks=[35,35,47,41,11,10,32,14,35,36,10,38]
96102

97103
class TestPullHistoric():
98104

0 commit comments

Comments
 (0)