@@ -118,15 +118,13 @@ def get_geo_signal_combos(data_source, api_key):
118
118
source_signal_mappings = {i ['source' ]:i ['db_source' ] for i in
119
119
meta_response .json ()}
120
120
121
- with warnings .catch_warnings ():
122
- warnings .simplefilter ("ignore" )
121
+ response = Epidata .covidcast_meta ()
123
122
124
- response = Epidata .covidcast_meta ()
125
-
126
- if response ["result" ] != 1 :
127
- # Something failed in the API and we did not get real metadata
128
- raise RuntimeError ("Error when fetching metadata from the API" , response ["message" ])
123
+ if response ["result" ] != 1 :
124
+ # Something failed in the API and we did not get real metadata
125
+ raise RuntimeError ("Error when fetching metadata from the API" , response ["message" ])
129
126
127
+ else :
130
128
meta = pd .DataFrame .from_dict (response ["epidata" ])
131
129
# note: this will fail for signals with weekly data, but currently not supported for validation
132
130
meta = meta [meta ["time_type" ] == "day" ]
@@ -183,12 +181,32 @@ def fetch_api_reference(data_source, start_date, end_date, geo_type, signal_type
183
181
time_type = "day" ,
184
182
geo_type = geo_type ,
185
183
time_values = Epidata .range (start_date .strftime ("%Y%m%d" ), end_date .strftime ("%Y%m%d" )),
186
- geo_value = "*"
184
+ geo_value = "*" ,
187
185
)
188
186
if response ["result" ] != 1 :
189
- # Something failed in the API and we did not get real metadata
187
+ # Something failed in the API and we did not get real signal data
190
188
raise RuntimeError ("Error when fetching signal data from the API" , response ["message" ])
191
189
190
+ if response ["message" ] not in {"success" , "no results" }:
191
+ warnings .warn (
192
+ "Problem obtaining data" ,
193
+ RuntimeWarning ,
194
+ message = response ["message" ],
195
+ data_source = data_source ,
196
+ signal = signal ,
197
+ time_value = params ["time_values" ],
198
+ geo_type = geo_type ,
199
+ )
200
+ logger .info (f"Trying calling covidcast again" )
201
+ response = Epidata .covidcast (
202
+ data_source ,
203
+ signal_type ,
204
+ time_type = "day" ,
205
+ geo_type = geo_type ,
206
+ time_values = Epidata .range (start_date .strftime ("%Y%m%d" ), end_date .strftime ("%Y%m%d" )),
207
+ geo_value = "*" ,
208
+ )
209
+
192
210
api_df = None
193
211
if len (response ["epidata" ]) > 0 :
194
212
api_df = pd .DataFrame .from_dict (response ["epidata" ])
@@ -204,8 +222,6 @@ def fetch_api_reference(data_source, start_date, end_date, geo_type, signal_type
204
222
205
223
if api_df is None :
206
224
raise APIDataFetchError ("Error: no API data was returned " + error_context )
207
- if not isinstance (api_df , pd .DataFrame ):
208
- raise APIDataFetchError ("Error: API return value was not a dataframe " + error_context )
209
225
210
226
column_names = ["geo_id" , "val" ,
211
227
"se" , "sample_size" , "time_value" ]
0 commit comments