19
19
from ._covidcast import define_covidcast_fields , GeoType , TimeType
20
20
21
21
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 :
25
23
if time_value == "*" :
26
24
if time_type == "day" :
27
25
return EpiRange ("10000101" , "30000101" )
@@ -35,28 +33,16 @@ def reformat_epirange(epirange: EpiRange, to_type: str) -> EpiRange:
35
33
if to_type not in ("day" , "week" ):
36
34
raise InvalidArgumentException ("`to_type` must be 'day' or 'week'" )
37
35
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 :
43
37
coercion_msg = (
44
38
"`collection_weeks` is in week format but `pub_covid_hosp_facility`"
45
39
"expects day format; dates will be converted to day format but may not"
46
40
"correspond exactly to desired time range"
47
41
)
48
42
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 ))
60
46
61
47
return epirange
62
48
@@ -98,9 +84,7 @@ def pvt_cdc(
98
84
epiweeks = get_wildcard_equivalent_dates (epiweeks , "day" )
99
85
100
86
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" )
104
88
105
89
return self ._create_call (
106
90
"cdc/" ,
@@ -132,9 +116,7 @@ def pub_covid_hosp_facility_lookup(
132
116
"""Lookup COVID hospitalization facility identifiers."""
133
117
134
118
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" )
138
120
139
121
return self ._create_call (
140
122
"covid_hosp_facility_lookup/" ,
@@ -168,9 +150,7 @@ def pub_covid_hosp_facility(
168
150
"""Fetch COVID hospitalization data for specific facilities."""
169
151
170
152
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" )
174
154
175
155
collection_weeks = get_wildcard_equivalent_dates (collection_weeks , "day" )
176
156
@@ -310,9 +290,7 @@ def pub_covid_hosp_state_timeseries(
310
290
raise InvalidArgumentException ("`states` and `dates` are both required" )
311
291
312
292
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" )
316
294
317
295
dates = get_wildcard_equivalent_dates (dates , "day" )
318
296
@@ -511,14 +489,10 @@ def pub_covidcast(
511
489
"`data_source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_values` are all required."
512
490
)
513
491
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." )
517
493
518
494
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." )
522
496
523
497
return self ._create_call (
524
498
"covidcast/" ,
@@ -552,16 +526,12 @@ def pub_delphi(self, system: str, epiweek: Union[int, str]) -> CALL_TYPE:
552
526
only_supports_classic = True ,
553
527
)
554
528
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 :
558
530
"""Fetch Delphi's dengue nowcast."""
559
531
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
560
532
561
533
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" )
565
535
566
536
return self ._create_call (
567
537
"dengue_nowcast/" ,
@@ -585,9 +555,7 @@ def pvt_dengue_sensors(
585
555
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
586
556
587
557
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" )
591
559
592
560
return self ._create_call (
593
561
"dengue_sensors/" ,
@@ -645,9 +613,7 @@ def pub_flusurv(
645
613
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
646
614
647
615
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" )
651
617
652
618
if issues is not None and lag is not None :
653
619
raise InvalidArgumentException ("`issues` and `lag` are mutually exclusive" )
@@ -764,16 +730,12 @@ def pub_fluview(
764
730
],
765
731
)
766
732
767
- def pub_gft (
768
- self , locations : StringParam , epiweeks : EpiRangeParam = "*"
769
- ) -> CALL_TYPE :
733
+ def pub_gft (self , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
770
734
"""Fetch Google Flu Trends data."""
771
735
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
772
736
773
737
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" )
777
739
778
740
return self ._create_call (
779
741
"gft/" ,
@@ -794,9 +756,7 @@ def pvt_ght(
794
756
) -> CALL_TYPE :
795
757
"""Fetch Google Health Trends data."""
796
758
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" )
800
760
801
761
return self ._create_call (
802
762
"ght/" ,
@@ -859,16 +819,12 @@ def pub_meta(self) -> CALL_TYPE:
859
819
only_supports_classic = True ,
860
820
)
861
821
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 :
865
823
"""Fetch NIDSS dengue data."""
866
824
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
867
825
868
826
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" )
872
828
873
829
return self ._create_call (
874
830
"nidss_dengue/" ,
@@ -909,16 +865,12 @@ def pub_nidss_flu(
909
865
],
910
866
)
911
867
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 :
915
869
"""Fetch NoroSTAT data (point data, no min/max)."""
916
870
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
917
871
918
872
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" )
922
874
923
875
return self ._create_call (
924
876
"norostat/" ,
@@ -930,16 +882,12 @@ def pvt_norostat(
930
882
],
931
883
)
932
884
933
- def pub_nowcast (
934
- self , locations : StringParam , epiweeks : EpiRangeParam = "*"
935
- ) -> CALL_TYPE :
885
+ def pub_nowcast (self , locations : StringParam , epiweeks : EpiRangeParam = "*" ) -> CALL_TYPE :
936
886
"""Fetch Delphi's wILI nowcast."""
937
887
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
938
888
939
889
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" )
943
891
944
892
return self ._create_call (
945
893
"nowcast/" ,
@@ -985,16 +933,12 @@ def pub_paho_dengue(
985
933
],
986
934
)
987
935
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 :
991
937
"""Fetch Quidel data."""
992
938
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
993
939
994
940
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" )
998
942
999
943
return self ._create_call (
1000
944
"quidel/" ,
@@ -1017,9 +961,7 @@ def pvt_sensors(
1017
961
epiweeks = get_wildcard_equivalent_dates (epiweeks , "week" )
1018
962
1019
963
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" )
1023
965
1024
966
return self ._create_call (
1025
967
"sensors/" ,
@@ -1061,9 +1003,7 @@ def pvt_twitter(
1061
1003
raise InvalidArgumentException ("`auth` and `locations` are both required" )
1062
1004
1063
1005
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" )
1067
1007
1068
1008
time_field = (
1069
1009
EpidataFieldInfo ("date" , EpidataFieldType .date )
@@ -1114,9 +1054,7 @@ def pub_wiki(
1114
1054
raise InvalidArgumentException ("`articles` is required" )
1115
1055
1116
1056
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" )
1120
1058
1121
1059
time_field = (
1122
1060
EpidataFieldInfo ("date" , EpidataFieldType .date )
0 commit comments