Skip to content

Commit bf21d33

Browse files
committed
more suggestion
1 parent 8e67b6c commit bf21d33

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

_delphi_utils_python/delphi_utils/validator/datafetcher.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,6 @@
1919
FILENAME_REGEX = re.compile(
2020
r'^(?P<date>\d{8})_(?P<geo_type>\w+?)_(?P<signal>\w+)\.csv$')
2121

22-
def _parse_datetimes(date_int: int, time_type: str, date_format: str = "%Y%m%d") -> Union[pd.Timestamp, None]:
23-
"""Convert a date or epiweeks string into timestamp objects.
24-
25-
Datetimes (length 8) are converted to their corresponding date, while epiweeks (length 6)
26-
are converted to the date of the start of the week. Returns nan otherwise
27-
28-
Epiweeks use the CDC format.
29-
30-
date_int: Int representation of date.
31-
time_type: The temporal resolution to request this data. Most signals
32-
are available at the "day" resolution (the default); some are only
33-
available at the "week" resolution, representing an MMWR week ("epiweek").
34-
date_format: String of the date format to parse.
35-
:returns: Timestamp.
36-
"""
37-
date_str = str(date_int)
38-
if time_type == "day":
39-
return pd.to_datetime(date_str, format=date_format)
40-
if time_type == "week":
41-
epiwk = Week(int(date_str[:4]), int(date_str[-2:]))
42-
return pd.to_datetime(epiwk.startdate())
43-
return None
44-
4522
def make_date_filter(start_date, end_date):
4623
"""
4724
Create a function to filter dates in the specified date range (inclusive).
@@ -150,8 +127,9 @@ def get_geo_signal_combos(data_source, api_key):
150127
raise RuntimeError("Error when fetching metadata from the API", response["message"])
151128

152129
meta = pd.DataFrame.from_dict(response["epidata"])
153-
meta["min_time"] = meta.apply(lambda x: _parse_datetimes(x.min_time, x.time_type), axis=1)
154-
meta["max_time"] = meta.apply(lambda x: _parse_datetimes(x.max_time, x.time_type), axis=1)
130+
# note: this will fail for signals with weekly data, but currently not supported for validation
131+
meta["min_time"] = meta.apply(lambda x: pd.to_datetime(str(x.min_time), format="%Y%m%d"), axis=1)
132+
meta["max_time"] = meta.apply(lambda x: pd.to_datetime(str(x.max_time), format="%Y%m%d"), axis=1)
155133
meta["last_update"] = pd.to_datetime(meta["last_update"], unit="s")
156134

157135
source_meta = meta[meta['data_source'] == data_source]

testing_utils/metadata_output.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)