1919from ._covidcast import define_covidcast_fields , GeoType , TimeType
2020
2121
22- def get_wildcard_equivalent_dates (
23- time_value : str , time_type : Literal ["day" , "week" ]
24- ) -> str :
22+ def get_wildcard_equivalent_dates (time_value : str , time_type : Literal ["day" , "week" ]) -> str :
2523 if time_value == "*" :
2624 if time_type == "day" :
2725 return EpiRange ("10000101" , "30000101" )
@@ -35,28 +33,16 @@ def reformat_epirange(epirange: EpiRange, to_type: str) -> EpiRange:
3533 if to_type not in ("day" , "week" ):
3634 raise InvalidArgumentException ("`to_type` must be 'day' or 'week'" )
3735
38- if (
39- to_type == "day"
40- and isinstance (epirange .start , (str , int ))
41- and len (str (epirange .start )) == 6
42- ):
36+ if to_type == "day" and isinstance (epirange .start , (str , int )) and len (str (epirange .start )) == 6 :
4337 coercion_msg = (
4438 "`collection_weeks` is in week format but `pub_covid_hosp_facility`"
4539 "expects day format; dates will be converted to day format but may not"
4640 "correspond exactly to desired time range"
4741 )
4842 warnings .warn (coercion_msg , UserWarning )
49- epirange = EpiRange (
50- parse_api_week (epirange .start ), parse_api_week (epirange .end )
51- )
52- elif (
53- to_type == "week"
54- and isinstance (epirange .start , (int , str ))
55- and len (str (epirange .start )) == 8
56- ):
57- epirange = EpiRange (
58- format_epiweek (epirange .start ), format_epiweek (epirange .end )
59- )
43+ epirange = EpiRange (parse_api_week (epirange .start ), parse_api_week (epirange .end ))
44+ elif to_type == "week" and isinstance (epirange .start , (int , str )) and len (str (epirange .start )) == 8 :
45+ epirange = EpiRange (format_epiweek (epirange .start ), format_epiweek (epirange .end ))
6046
6147 return epirange
6248
@@ -98,9 +84,7 @@ def pvt_cdc(
9884 epiweeks = get_wildcard_equivalent_dates (epiweeks , "day" )
9985
10086 if auth is None or epiweeks is None or locations is None :
101- raise InvalidArgumentException (
102- "`auth`, `epiweeks`, and `locations` are all required"
103- )
87+ raise InvalidArgumentException ("`auth`, `epiweeks`, and `locations` are all required" )
10488
10589 return self ._create_call (
10690 "cdc/" ,
@@ -132,9 +116,7 @@ def pub_covid_hosp_facility_lookup(
132116 """Lookup COVID hospitalization facility identifiers."""
133117
134118 if all ((v is None for v in (state , ccn , city , zip , fips_code ))):
135- raise InvalidArgumentException (
136- "one of `state`, `ccn`, `city`, `zip`, or `fips_code` is required"
137- )
119+ raise InvalidArgumentException ("one of `state`, `ccn`, `city`, `zip`, or `fips_code` is required" )
138120
139121 return self ._create_call (
140122 "covid_hosp_facility_lookup/" ,
@@ -168,9 +150,7 @@ def pub_covid_hosp_facility(
168150 """Fetch COVID hospitalization data for specific facilities."""
169151
170152 if hospital_pks is None or collection_weeks is None :
171- raise InvalidArgumentException (
172- "`hospital_pks` and `collection_weeks` are both required"
173- )
153+ raise InvalidArgumentException ("`hospital_pks` and `collection_weeks` are both required" )
174154
175155 collection_weeks = get_wildcard_equivalent_dates (collection_weeks , "day" )
176156
@@ -310,9 +290,7 @@ def pub_covid_hosp_state_timeseries(
310290 raise InvalidArgumentException ("`states` and `dates` are both required" )
311291
312292 if issues is not None and as_of is not None :
313- raise InvalidArgumentException (
314- "`issues` and `as_of` are mutually exclusive"
315- )
293+ raise InvalidArgumentException ("`issues` and `as_of` are mutually exclusive" )
316294
317295 dates = get_wildcard_equivalent_dates (dates , "day" )
318296
@@ -511,14 +489,10 @@ def pub_covidcast(
511489 "`data_source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_values` are all required."
512490 )
513491 if sum ([issues is not None , lag is not None , as_of is not None ]) > 1 :
514- raise InvalidArgumentException (
515- "`issues`, `lag`, and `as_of` are mutually exclusive."
516- )
492+ raise InvalidArgumentException ("`issues`, `lag`, and `as_of` are mutually exclusive." )
517493
518494 if data_source == "nchs-mortality" and time_type != "week" :
519- raise InvalidArgumentException (
520- "nchs-mortality data source only supports the week time type."
521- )
495+ raise InvalidArgumentException ("nchs-mortality data source only supports the week time type." )
522496
523497 return self ._create_call (
524498 "covidcast/" ,
@@ -552,16 +526,12 @@ def pub_delphi(self, system: str, epiweek: Union[int, str]) -> CALL_TYPE:
552526 only_supports_classic = True ,
553527 )
554528
555- def pub_dengue_nowcast (
556- self , locations : StringParam , epiweeks : EpiRangeParam = "*"
557- ) -> CALL_TYPE :
529+ def pub_dengue_nowcast (self , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
558530 """Fetch Delphi's dengue nowcast."""
559531 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
560532
561533 if locations is None or epiweeks is None :
562- raise InvalidArgumentException (
563- "`locations` and `epiweeks` are both required"
564- )
534+ raise InvalidArgumentException ("`locations` and `epiweeks` are both required" )
565535
566536 return self ._create_call (
567537 "dengue_nowcast/" ,
@@ -585,9 +555,7 @@ def pvt_dengue_sensors(
585555 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
586556
587557 if auth is None or names is None or locations is None or epiweeks is None :
588- raise InvalidArgumentException (
589- "`auth`, `names`, `locations`, and `epiweeks` are all required"
590- )
558+ raise InvalidArgumentException ("`auth`, `names`, `locations`, and `epiweeks` are all required" )
591559
592560 return self ._create_call (
593561 "dengue_sensors/" ,
@@ -645,9 +613,7 @@ def pub_flusurv(
645613 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
646614
647615 if locations is None or epiweeks is None :
648- raise InvalidArgumentException (
649- "`locations` and `epiweeks` are both required"
650- )
616+ raise InvalidArgumentException ("`locations` and `epiweeks` are both required" )
651617
652618 if issues is not None and lag is not None :
653619 raise InvalidArgumentException ("`issues` and `lag` are mutually exclusive" )
@@ -764,16 +730,12 @@ def pub_fluview(
764730 ],
765731 )
766732
767- def pub_gft (
768- self , locations : StringParam , epiweeks : EpiRangeParam = "*"
769- ) -> CALL_TYPE :
733+ def pub_gft (self , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
770734 """Fetch Google Flu Trends data."""
771735 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
772736
773737 if locations is None or epiweeks is None :
774- raise InvalidArgumentException (
775- "`locations` and `epiweeks` are both required"
776- )
738+ raise InvalidArgumentException ("`locations` and `epiweeks` are both required" )
777739
778740 return self ._create_call (
779741 "gft/" ,
@@ -794,9 +756,7 @@ def pvt_ght(
794756 ) -> CALL_TYPE :
795757 """Fetch Google Health Trends data."""
796758 if auth is None or locations is None or epiweeks is None or query == "" :
797- raise InvalidArgumentException (
798- "`auth`, `locations`, `epiweeks`, and `query` are all required"
799- )
759+ raise InvalidArgumentException ("`auth`, `locations`, `epiweeks`, and `query` are all required" )
800760
801761 return self ._create_call (
802762 "ght/" ,
@@ -859,16 +819,12 @@ def pub_meta(self) -> CALL_TYPE:
859819 only_supports_classic = True ,
860820 )
861821
862- def pub_nidss_dengue (
863- self , locations : StringParam , epiweeks : EpiRangeParam = "*"
864- ) -> CALL_TYPE :
822+ def pub_nidss_dengue (self , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
865823 """Fetch NIDSS dengue data."""
866824 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
867825
868826 if locations is None or epiweeks is None :
869- raise InvalidArgumentException (
870- "`locations` and `epiweeks` are both required"
871- )
827+ raise InvalidArgumentException ("`locations` and `epiweeks` are both required" )
872828
873829 return self ._create_call (
874830 "nidss_dengue/" ,
@@ -909,16 +865,12 @@ def pub_nidss_flu(
909865 ],
910866 )
911867
912- def pvt_norostat (
913- self , auth : str , location : str , epiweeks : EpiRangeParam = "*"
914- ) -> CALL_TYPE :
868+ def pvt_norostat (self , auth : str , location : str , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
915869 """Fetch NoroSTAT data (point data, no min/max)."""
916870 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
917871
918872 if auth is None or location is None or epiweeks is None :
919- raise InvalidArgumentException (
920- "`auth`, `location`, and `epiweeks` are all required"
921- )
873+ raise InvalidArgumentException ("`auth`, `location`, and `epiweeks` are all required" )
922874
923875 return self ._create_call (
924876 "norostat/" ,
@@ -930,16 +882,12 @@ def pvt_norostat(
930882 ],
931883 )
932884
933- def pub_nowcast (
934- self , locations : StringParam , epiweeks : EpiRangeParam = "*"
935- ) -> CALL_TYPE :
885+ def pub_nowcast (self , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
936886 """Fetch Delphi's wILI nowcast."""
937887 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
938888
939889 if locations is None or epiweeks is None :
940- raise InvalidArgumentException (
941- "`locations` and `epiweeks` are both required"
942- )
890+ raise InvalidArgumentException ("`locations` and `epiweeks` are both required" )
943891
944892 return self ._create_call (
945893 "nowcast/" ,
@@ -985,16 +933,12 @@ def pub_paho_dengue(
985933 ],
986934 )
987935
988- def pvt_quidel (
989- self , auth : str , locations : StringParam , epiweeks : EpiRangeParam = "*"
990- ) -> CALL_TYPE :
936+ def pvt_quidel (self , auth : str , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
991937 """Fetch Quidel data."""
992938 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
993939
994940 if auth is None or epiweeks is None or locations is None :
995- raise InvalidArgumentException (
996- "`auth`, `epiweeks`, and `locations` are all required"
997- )
941+ raise InvalidArgumentException ("`auth`, `epiweeks`, and `locations` are all required" )
998942
999943 return self ._create_call (
1000944 "quidel/" ,
@@ -1017,9 +961,7 @@ def pvt_sensors(
1017961 epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
1018962
1019963 if auth is None or names is None or locations is None or epiweeks is None :
1020- raise InvalidArgumentException (
1021- "`auth`, `names`, `locations`, and `epiweeks` are all required"
1022- )
964+ raise InvalidArgumentException ("`auth`, `names`, `locations`, and `epiweeks` are all required" )
1023965
1024966 return self ._create_call (
1025967 "sensors/" ,
@@ -1061,9 +1003,7 @@ def pvt_twitter(
10611003 raise InvalidArgumentException ("`auth` and `locations` are both required" )
10621004
10631005 if not (dates is None ) ^ (epiweeks is None ):
1064- raise InvalidArgumentException (
1065- "exactly one of `dates` and `epiweeks` is required"
1066- )
1006+ raise InvalidArgumentException ("exactly one of `dates` and `epiweeks` is required" )
10671007
10681008 time_field = (
10691009 EpidataFieldInfo ("date" , EpidataFieldType .date )
@@ -1114,9 +1054,7 @@ def pub_wiki(
11141054 raise InvalidArgumentException ("`articles` is required" )
11151055
11161056 if not (dates is None ) ^ (epiweeks is None ):
1117- raise InvalidArgumentException (
1118- "exactly one of `dates` and `epiweeks` is required"
1119- )
1057+ raise InvalidArgumentException ("exactly one of `dates` and `epiweeks` is required" )
11201058
11211059 time_field = (
11221060 EpidataFieldInfo ("date" , EpidataFieldType .date )
0 commit comments