Skip to content

Commit a6a1c98

Browse files
committed
refactor: remove endpoint arg None checking
1 parent caedb4f commit a6a1c98

File tree

1 file changed

+9
-92
lines changed

1 file changed

+9
-92
lines changed

epidatpy/_endpoints.py

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ def pvt_cdc(
7474
"""Fetch CDC page hits."""
7575
epiweeks = get_wildcard_equivalent_dates(epiweeks, "day")
7676

77-
if auth is None or epiweeks is None or locations is None:
78-
raise InvalidArgumentException("`auth`, `epiweeks`, and `locations` are all required")
79-
8077
return self._create_call(
8178
"cdc/",
8279
{"auth": auth, "epiweeks": epiweeks, "locations": locations},
@@ -140,18 +137,15 @@ def pub_covid_hosp_facility(
140137
) -> CALL_TYPE:
141138
"""Fetch COVID hospitalization data for specific facilities."""
142139

143-
if hospital_pks is None or collection_weeks is None:
144-
raise InvalidArgumentException("`hospital_pks` and `collection_weeks` are both required")
145-
146140
collection_weeks = get_wildcard_equivalent_dates(collection_weeks, "day")
147141

148142
# Confusingly, the endpoint expects `collection_weeks` to be in day format,
149143
# but correspond to epiweeks. Allow `collection_weeks` to be provided in
150144
# either day or week format.
151145
if isinstance(collection_weeks, EpiRange):
152-
collection_weeks = reformat_epirange(collection_weeks, to_type="day")
146+
parsed_weeks = reformat_epirange(collection_weeks, to_type="day")
153147
elif isinstance(collection_weeks, (str, int)):
154-
collection_weeks = parse_api_week(collection_weeks)
148+
parsed_weeks = parse_api_week(collection_weeks)
155149

156150
fields_string = [
157151
"hospital_pk",
@@ -255,7 +249,7 @@ def pub_covid_hosp_facility(
255249
"covid_hosp_facility/",
256250
{
257251
"hospital_pks": hospital_pks,
258-
"collection_weeks": collection_weeks,
252+
"collection_weeks": parsed_weeks,
259253
"publication_dates": publication_dates,
260254
},
261255
[
@@ -277,9 +271,6 @@ def pub_covid_hosp_state_timeseries(
277271
) -> CALL_TYPE:
278272
"""Fetch COVID hospitalization data."""
279273

280-
if states is None or dates is None:
281-
raise InvalidArgumentException("`states` and `dates` are both required")
282-
283274
if issues is not None and as_of is not None:
284275
raise InvalidArgumentException("`issues` and `as_of` are mutually exclusive")
285276

@@ -465,20 +456,6 @@ def pub_covidcast(
465456
lag: Optional[int] = None,
466457
) -> CALL_TYPE:
467458
"""Fetch Delphi's COVID-19 Surveillance Streams"""
468-
if any(
469-
v is None
470-
for v in (
471-
data_source,
472-
signals,
473-
time_type,
474-
geo_type,
475-
time_values,
476-
geo_values,
477-
)
478-
):
479-
raise InvalidArgumentException(
480-
"`data_source`, `signals`, `time_type`, `geo_type`, `time_values`, and `geo_values` are all required."
481-
)
482459
if sum([issues is not None, lag is not None, as_of is not None]) > 1:
483460
raise InvalidArgumentException("`issues`, `lag`, and `as_of` are mutually exclusive.")
484461

@@ -504,8 +481,6 @@ def pub_covidcast(
504481
def pub_delphi(self, system: str, epiweek: Union[int, str]) -> CALL_TYPE:
505482
"""Fetch Delphi's forecast."""
506483

507-
if system is None or epiweek is None:
508-
raise InvalidArgumentException("`system` and `epiweek` are both required")
509484
return self._create_call(
510485
"delphi/",
511486
{"system": system, "epiweek": epiweek},
@@ -521,9 +496,6 @@ def pub_dengue_nowcast(self, locations: StringParam, epiweeks: EpiRangeParam = "
521496
"""Fetch Delphi's dengue nowcast."""
522497
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
523498

524-
if locations is None or epiweeks is None:
525-
raise InvalidArgumentException("`locations` and `epiweeks` are both required")
526-
527499
return self._create_call(
528500
"dengue_nowcast/",
529501
{"locations": locations, "epiweeks": epiweeks},
@@ -545,9 +517,6 @@ def pvt_dengue_sensors(
545517
"""Fetch Delphi's digital surveillance sensors."""
546518
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
547519

548-
if auth is None or names is None or locations is None or epiweeks is None:
549-
raise InvalidArgumentException("`auth`, `names`, `locations`, and `epiweeks` are all required")
550-
551520
return self._create_call(
552521
"dengue_sensors/",
553522
{
@@ -574,9 +543,6 @@ def pub_ecdc_ili(
574543
"""Fetch ECDC ILI data."""
575544
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
576545

577-
if regions is None or epiweeks is None:
578-
raise InvalidArgumentException("`regions` and `epiweeks` are both required")
579-
580546
if issues is not None and lag is not None:
581547
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
582548

@@ -603,9 +569,6 @@ def pub_flusurv(
603569
"""Fetch FluSurv data."""
604570
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
605571

606-
if locations is None or epiweeks is None:
607-
raise InvalidArgumentException("`locations` and `epiweeks` are both required")
608-
609572
if issues is not None and lag is not None:
610573
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
611574

@@ -642,9 +605,6 @@ def pub_fluview_clinical(
642605
"""Fetch FluView clinical data."""
643606
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
644607

645-
if regions is None or epiweeks is None:
646-
raise InvalidArgumentException("`regions` and `epiweeks` are both required")
647-
648608
if issues is not None and lag is not None:
649609
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
650610

@@ -687,9 +647,6 @@ def pub_fluview(
687647
) -> CALL_TYPE:
688648
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
689649

690-
if regions is None or epiweeks is None:
691-
raise InvalidArgumentException("`regions` and `epiweeks` are both required")
692-
693650
if issues is not None and lag is not None:
694651
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
695652

@@ -725,9 +682,6 @@ def pub_gft(self, locations: StringParam, epiweeks: EpiRangeParam = "*") -> CALL
725682
"""Fetch Google Flu Trends data."""
726683
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
727684

728-
if locations is None or epiweeks is None:
729-
raise InvalidArgumentException("`locations` and `epiweeks` are both required")
730-
731685
return self._create_call(
732686
"gft/",
733687
{"locations": locations, "epiweeks": epiweeks},
@@ -746,7 +700,7 @@ def pvt_ght(
746700
query: str = "",
747701
) -> CALL_TYPE:
748702
"""Fetch Google Health Trends data."""
749-
if auth is None or locations is None or epiweeks is None or query == "":
703+
if auth is None or locations is None or query == "":
750704
raise InvalidArgumentException("`auth`, `locations`, `epiweeks`, and `query` are all required")
751705

752706
return self._create_call(
@@ -774,8 +728,6 @@ def pub_kcdc_ili(
774728
"""Fetch KCDC ILI data."""
775729
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
776730

777-
if regions is None or epiweeks is None:
778-
raise InvalidArgumentException("`regions` and `epiweeks` are both required")
779731
if issues is not None and lag is not None:
780732
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
781733

@@ -794,8 +746,6 @@ def pub_kcdc_ili(
794746

795747
def pvt_meta_norostat(self, auth: str) -> CALL_TYPE:
796748
"""Fetch NoroSTAT metadata."""
797-
if auth is None:
798-
raise InvalidArgumentException("`auth` is required")
799749
return self._create_call(
800750
"meta_norostat/",
801751
{"auth": auth},
@@ -814,9 +764,6 @@ def pub_nidss_dengue(self, locations: StringParam, epiweeks: EpiRangeParam = "*"
814764
"""Fetch NIDSS dengue data."""
815765
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
816766

817-
if locations is None or epiweeks is None:
818-
raise InvalidArgumentException("`locations` and `epiweeks` are both required")
819-
820767
return self._create_call(
821768
"nidss_dengue/",
822769
{"locations": locations, "epiweeks": epiweeks},
@@ -837,8 +784,6 @@ def pub_nidss_flu(
837784
"""Fetch NIDSS flu data."""
838785
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
839786

840-
if regions is None or epiweeks is None:
841-
raise InvalidArgumentException("`regions` and `epiweeks` are both required")
842787
if issues is not None and lag is not None:
843788
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
844789

@@ -860,9 +805,6 @@ def pvt_norostat(self, auth: str, location: str, epiweeks: EpiRangeParam = "*")
860805
"""Fetch NoroSTAT data (point data, no min/max)."""
861806
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
862807

863-
if auth is None or location is None or epiweeks is None:
864-
raise InvalidArgumentException("`auth`, `location`, and `epiweeks` are all required")
865-
866808
return self._create_call(
867809
"norostat/",
868810
{"auth": auth, "epiweeks": epiweeks, "location": location},
@@ -877,9 +819,6 @@ def pub_nowcast(self, locations: StringParam, epiweeks: EpiRangeParam = "*") ->
877819
"""Fetch Delphi's wILI nowcast."""
878820
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
879821

880-
if locations is None or epiweeks is None:
881-
raise InvalidArgumentException("`locations` and `epiweeks` are both required")
882-
883822
return self._create_call(
884823
"nowcast/",
885824
{"locations": locations, "epiweeks": epiweeks},
@@ -901,8 +840,6 @@ def pub_paho_dengue(
901840
"""Fetch PAHO Dengue data."""
902841
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
903842

904-
if regions is None or epiweeks is None:
905-
raise InvalidArgumentException("`regions` and `epiweeks` are both required")
906843
if issues is not None and lag is not None:
907844
raise InvalidArgumentException("`issues` and `lag` are mutually exclusive")
908845

@@ -928,9 +865,6 @@ def pvt_quidel(self, auth: str, locations: StringParam, epiweeks: EpiRangeParam
928865
"""Fetch Quidel data."""
929866
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
930867

931-
if auth is None or epiweeks is None or locations is None:
932-
raise InvalidArgumentException("`auth`, `epiweeks`, and `locations` are all required")
933-
934868
return self._create_call(
935869
"quidel/",
936870
{"auth": auth, "epiweeks": epiweeks, "locations": locations},
@@ -951,9 +885,6 @@ def pvt_sensors(
951885
"""Fetch Delphi's digital surveillance sensors."""
952886
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
953887

954-
if auth is None or names is None or locations is None or epiweeks is None:
955-
raise InvalidArgumentException("`auth`, `names`, `locations`, and `epiweeks` are all required")
956-
957888
return self._create_call(
958889
"sensors/",
959890
{
@@ -987,12 +918,6 @@ def pvt_twitter(
987918
dates = None
988919
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
989920

990-
if auth is None or locations is None:
991-
raise InvalidArgumentException("`auth` and `locations` are both required")
992-
993-
if not (dates is None) ^ (epiweeks is None):
994-
raise InvalidArgumentException("exactly one of `dates` and `epiweeks` is required")
995-
996921
time_field = (
997922
EpidataFieldInfo("date", EpidataFieldType.date)
998923
if dates
@@ -1034,18 +959,6 @@ def pub_wiki(
1034959
dates = None
1035960
epiweeks = get_wildcard_equivalent_dates(epiweeks, "week")
1036961

1037-
if articles is None:
1038-
raise InvalidArgumentException("`articles` is required")
1039-
1040-
if not (dates is None) ^ (epiweeks is None):
1041-
raise InvalidArgumentException("exactly one of `dates` and `epiweeks` is required")
1042-
1043-
time_field = (
1044-
EpidataFieldInfo("date", EpidataFieldType.date)
1045-
if dates
1046-
else EpidataFieldInfo("epiweek", EpidataFieldType.epiweek)
1047-
)
1048-
1049962
return self._create_call(
1050963
"wiki/",
1051964
{
@@ -1057,7 +970,11 @@ def pub_wiki(
1057970
},
1058971
[
1059972
EpidataFieldInfo("article", EpidataFieldType.text),
1060-
time_field,
973+
(
974+
EpidataFieldInfo("date", EpidataFieldType.date)
975+
if dates
976+
else EpidataFieldInfo("epiweek", EpidataFieldType.epiweek)
977+
),
1061978
EpidataFieldInfo("count", EpidataFieldType.int),
1062979
EpidataFieldInfo("total", EpidataFieldType.int),
1063980
EpidataFieldInfo("hour", EpidataFieldType.int),

0 commit comments

Comments
 (0)