Skip to content

Commit e5c3b46

Browse files
committed
delphi_utils/validator/datafetcher.py
1 parent 23384e7 commit e5c3b46

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

_delphi_utils_python/delphi_utils/validator/datafetcher.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,21 @@ def get_geo_signal_combos(data_source, api_key):
120120
source_signal_mappings = {i['source']:i['db_source'] for i in
121121
meta_response.json()}
122122

123-
response = Epidata.covidcast_meta()
123+
with warnings.catch_warnings():
124+
warnings.simplefilter("ignore")
124125

125-
if response["result"] != 1:
126-
# Something failed in the API and we did not get real metadata
127-
raise RuntimeError("Error when fetching metadata from the API", response["message"])
126+
response = Epidata.covidcast_meta()
127+
128+
if response["result"] != 1:
129+
# Something failed in the API and we did not get real metadata
130+
raise RuntimeError("Error when fetching metadata from the API", response["message"])
128131

129-
meta = pd.DataFrame.from_dict(response["epidata"])
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)
133-
meta["last_update"] = pd.to_datetime(meta["last_update"], unit="s")
132+
meta = pd.DataFrame.from_dict(response["epidata"])
133+
# note: this will fail for signals with weekly data, but currently not supported for validation
134+
meta = meta[meta["time_type"] == "day"]
135+
meta["min_time"] = meta.apply(lambda x: pd.to_datetime(str(x.min_time), format="%Y%m%d"), axis=1)
136+
meta["max_time"] = meta.apply(lambda x: pd.to_datetime(str(x.max_time), format="%Y%m%d"), axis=1)
137+
meta["last_update"] = pd.to_datetime(meta["last_update"], unit="s")
134138

135139
source_meta = meta[meta['data_source'] == data_source]
136140
# Need to convert np.records to tuples so they are hashable and can be used in sets and dicts.
@@ -184,7 +188,7 @@ def fetch_api_reference(data_source, start_date, end_date, geo_type, signal_type
184188
time_type="day",
185189
geo_type=geo_type,
186190
time_values=Epidata.range(start_date.strftime("%Y%m%d"), end_date.strftime("%Y%m%d")),
187-
geo_value=geo_type,
191+
geo_value="*"
188192
)
189193
if response["result"] != 1:
190194
# Something failed in the API and we did not get real metadata
@@ -193,6 +197,7 @@ def fetch_api_reference(data_source, start_date, end_date, geo_type, signal_type
193197
api_df = None
194198
if len(response["epidata"]) > 0:
195199
api_df = pd.DataFrame.from_dict(response["epidata"])
200+
# note: this will fail for signals with weekly data, but currently not supported for validation
196201
api_df["issue"] = pd.to_datetime(api_df["issue"], format="%Y%m%d")
197202
api_df["time_value"] = pd.to_datetime(api_df["time_value"], format="%Y%m%d")
198203
api_df.drop("direction", axis=1, inplace=True)

0 commit comments

Comments
 (0)