9
9
Union ,
10
10
)
11
11
12
+ from epiweeks import Week
13
+
12
14
from ._covidcast import GeoType , TimeType , define_covidcast_fields
13
15
from ._model import (
14
16
CALL_TYPE ,
20
22
InvalidArgumentException ,
21
23
ParamType ,
22
24
StringParam ,
23
- format_epiweek ,
24
25
)
25
- from ._parse import parse_api_week
26
+ from ._parse import parse_user_date_or_week
26
27
27
28
28
29
def get_wildcard_equivalent_dates (time_value : EpiRangeParam , time_type : Literal ["day" , "week" ]) -> EpiRangeParam :
@@ -34,22 +35,6 @@ def get_wildcard_equivalent_dates(time_value: EpiRangeParam, time_type: Literal[
34
35
return time_value
35
36
36
37
37
- def reformat_epirange (epirange : EpiRange , to_type : Literal ["day" , "week" ]) -> EpiRange :
38
- """Reformat from week to day or vice versa or noop."""
39
- if to_type == "day" and isinstance (epirange .start , (str , int )) and len (str (epirange .start )) == 6 :
40
- coercion_msg = (
41
- "`collection_weeks` is in week format but `pub_covid_hosp_facility`"
42
- "expects day format; dates will be converted to day format but may not"
43
- "correspond exactly to desired time range"
44
- )
45
- warnings .warn (coercion_msg , UserWarning )
46
- epirange = EpiRange (parse_api_week (epirange .start ), parse_api_week (epirange .end ))
47
- elif to_type == "week" and isinstance (epirange .start , (int , str )) and len (str (epirange .start )) == 8 :
48
- epirange = EpiRange (format_epiweek (epirange .start ), format_epiweek (epirange .end ))
49
-
50
- return epirange
51
-
52
-
53
38
class AEpiDataEndpoints (ABC , Generic [CALL_TYPE ]):
54
39
"""
55
40
epidata endpoint list and fetcher
@@ -141,11 +126,27 @@ def pub_covid_hosp_facility(
141
126
142
127
# Confusingly, the endpoint expects `collection_weeks` to be in day format,
143
128
# but correspond to epiweeks. Allow `collection_weeks` to be provided in
144
- # either day or week format.
145
- if isinstance (collection_weeks , EpiRange ):
146
- parsed_weeks = reformat_epirange (collection_weeks , to_type = "day" )
147
- elif isinstance (collection_weeks , (str , int )):
148
- parsed_weeks = parse_api_week (collection_weeks )
129
+ # either day or week format and convert to day format.
130
+ parsed_weeks = collection_weeks
131
+ if isinstance (collection_weeks , EpiRange ) and isinstance (collection_weeks .start , Week ):
132
+ warnings .warn (
133
+ "`collection_weeks` is in week format but `pub_covid_hosp_facility`"
134
+ "expects day format; dates will be converted to day format but may not"
135
+ "correspond exactly to desired time range" ,
136
+ UserWarning ,
137
+ )
138
+ parsed_weeks = EpiRange (
139
+ parse_user_date_or_week (collection_weeks .start , "day" ),
140
+ parse_user_date_or_week (collection_weeks .end , "day" ),
141
+ )
142
+ elif isinstance (collection_weeks , (str , int )) and len (str (collection_weeks )) == 6 :
143
+ warnings .warn (
144
+ "`collection_weeks` is in week format but `pub_covid_hosp_facility`"
145
+ "expects day format; dates will be converted to day format but may not"
146
+ "correspond exactly to desired time range" ,
147
+ UserWarning ,
148
+ )
149
+ parsed_weeks = parse_user_date_or_week (collection_weeks , "day" )
149
150
150
151
fields_string = [
151
152
"hospital_pk" ,
0 commit comments