|
10 | 10 | import pandas as pd
|
11 | 11 | import numpy as np
|
12 | 12 | import covidcast
|
| 13 | +from delphi_epidata import Epidata |
13 | 14 | from .errors import APIDataFetchError, ValidationFailure
|
14 | 15 |
|
15 | 16 | FILENAME_REGEX = re.compile(
|
@@ -115,7 +116,16 @@ def get_geo_signal_combos(data_source, api_key):
|
115 | 116 | meta_response.raise_for_status()
|
116 | 117 | source_signal_mappings = {i['source']:i['db_source'] for i in
|
117 | 118 | meta_response.json()}
|
118 |
| - meta = covidcast.metadata() |
| 119 | + |
| 120 | + response = Epidata._request("covidcast_meta") |
| 121 | + |
| 122 | + if response["result"] != 1: |
| 123 | + # Something failed in the API and we did not get real metadata |
| 124 | + raise RuntimeError("Error when fetching metadata from the API", |
| 125 | + response["message"]) |
| 126 | + |
| 127 | + meta = pd.DataFrame.from_dict(response["epidata"]) |
| 128 | + |
119 | 129 | source_meta = meta[meta['data_source'] == data_source]
|
120 | 130 | # Need to convert np.records to tuples so they are hashable and can be used in sets and dicts.
|
121 | 131 | geo_signal_combos = list(map(tuple,
|
@@ -160,8 +170,38 @@ def fetch_api_reference(data_source, start_date, end_date, geo_type, signal_type
|
160 | 170 | """
|
161 | 171 | with warnings.catch_warnings():
|
162 | 172 | warnings.simplefilter("ignore")
|
163 |
| - api_df = covidcast.signal( |
164 |
| - data_source, signal_type, start_date, end_date, geo_type) |
| 173 | + # api_df = covidcast.signal( |
| 174 | + # data_source, signal_type, start_date, end_date, geo_type) |
| 175 | + |
| 176 | + response = Epidata.covidcast(data_source, signal_type, time_type="day", |
| 177 | + geo_type=geo_type, time_values=[start_date, end_date], |
| 178 | + geo_value="*", as_of=None, |
| 179 | + issues=None, lag=None) |
| 180 | + |
| 181 | + if response["result"] != 1: |
| 182 | + # Something failed in the API and we did not get real metadata |
| 183 | + raise RuntimeError("Error when fetching metadata from the API", |
| 184 | + response["message"]) |
| 185 | + |
| 186 | + api_df = pd.DataFrame.from_dict(response["epidata"]) |
| 187 | + |
| 188 | + # # Two possible error conditions: no data or too much data. |
| 189 | + # if day_data["message"] == "no results": |
| 190 | + # warnings.warn(f"No {data_source} {signal} data found on {day_str} " |
| 191 | + # f"for geography '{geo_type}'", |
| 192 | + # NoDataWarning) |
| 193 | + # if day_data["message"] not in {"success", "no results"}: |
| 194 | + # warnings.warn(f"Problem obtaining {data_source} {signal} data on {day_str} " |
| 195 | + # f"for geography '{geo_type}': {day_data['message']}", |
| 196 | + # RuntimeWarning) |
| 197 | + # |
| 198 | + # # In the too-much-data case, we continue to try putting the truncated |
| 199 | + # # data in our results. In the no-data case, skip this day entirely, |
| 200 | + # # since there is no "epidata" in the response. |
| 201 | + # if day_data.get("epidata"): |
| 202 | + # dfs.append(pd.DataFrame.from_dict(day_data["epidata"])) |
| 203 | + # cur_day += timedelta(1) if time_type == "day" else timedelta(7) |
| 204 | + # |
165 | 205 |
|
166 | 206 | error_context = f"when fetching reference data from {start_date} to {end_date} " +\
|
167 | 207 | f"for data source: {data_source}, signal type: {signal_type}, geo type: {geo_type}"
|
|
0 commit comments