@@ -154,92 +154,6 @@ def check_metadata():
154154 assert_frame_equal (expected_df , df )
155155
156156
157- def ported_signal (
158- data_source : str ,
159- signal : str , # pylint: disable=W0621
160- start_day : date = None ,
161- end_day : date = None ,
162- geo_type : str = "county" ,
163- geo_values : Union [str , Iterable [str ]] = "*" ,
164- as_of : date = None ,
165- lag : int = None ,
166- time_type : str = "day" ,
167- ) -> Union [pd .DataFrame , None ]:
168- """
169- Makes covidcast signal api call.
170-
171- data_source: String identifying the data source to query, such as
172- ``"fb-survey"``.
173- signal: String identifying the signal from that source to query,
174- such as ``"smoothed_cli"``.
175- start_day: Query data beginning on this date. Provided as a
176- ``datetime.date`` object. If ``start_day`` is ``None``, defaults to the
177- first day data is available for this signal. If ``time_type == "week"``, then
178- this is rounded to the epiweek containing the day (i.e. the previous Sunday).
179- end_day: Query data up to this date, inclusive. Provided as a
180- ``datetime.date`` object. If ``end_day`` is ``None``, defaults to the most
181- recent day data is available for this signal. If ``time_type == "week"``, then
182- this is rounded to the epiweek containing the day (i.e. the previous Sunday).
183- geo_type: The geography type for which to request this data, such as
184- ``"county"`` or ``"state"``. Available types are described in the
185- COVIDcast signal documentation. Defaults to ``"county"``.
186- geo_values: The geographies to fetch data for. The default, ``"*"``,
187- fetches all geographies. To fetch one geography, specify its ID as a
188- string; multiple geographies can be provided as an iterable (list, tuple,
189- ...) of strings.
190- as_of: Fetch only data that was available on or before this date,
191- provided as a ``datetime.date`` object. If ``None``, the default, return
192- the most recent available data. If ``time_type == "week"``, then
193- this is rounded to the epiweek containing the day (i.e. the previous Sunday).
194- lag: Integer. If, for example, ``lag=3``, fetch only data that was
195- published or updated exactly 3 days after the date. For example, a row
196- with ``time_value`` of June 3 will only be included in the results if its
197- data was issued or updated on June 6. If ``None``, the default, return the
198- most recently issued data regardless of its lag.
199- time_type: The temporal resolution to request this data. Most signals
200- are available at the "day" resolution (the default); some are only
201- available at the "week" resolution, representing an MMWR week ("epiweek").
202- :returns: A Pandas data frame with matching data, or ``None`` if no data is
203- returned. Each row is one observation on one day in one geographic location.
204- Contains the following columns:
205- """
206- if start_day > end_day :
207- raise ValueError (
208- "end_day must be on or after start_day, but " f"start_day = '{ start_day } ', end_day = '{ end_day } '"
209- )
210-
211- if time_type == "day" :
212- time_values = Epidata .range (start_day .strftime ("%Y%m%d" ), end_day .strftime ("%Y%m%d" ))
213- else :
214- time_values = Epidata .range (start_day .strftime ("%Y%W" ), end_day .strftime ("%Y%W" ))
215- response = Epidata .covidcast (
216- data_source ,
217- signal ,
218- time_type = time_type ,
219- geo_type = geo_type ,
220- time_values = time_values ,
221- geo_value = geo_values ,
222- as_of = as_of ,
223- lag = lag ,
224- )
225-
226- if response ["result" ] != 1 :
227- print (f"check { data_source } { signal } " )
228- # Something failed in the API and we did not get real metadata
229- # raise RuntimeError("Error when fetching signal data from the API", response["message"])
230-
231- api_df = pd .DataFrame .from_dict (response ["epidata" ])
232- if not api_df .empty :
233- time_type = api_df ["time_type" ].values [0 ]
234- api_df = _parse_datetimes (api_df , "time_value" , time_type )
235- api_df = _parse_datetimes (api_df , "issue" , time_type )
236- api_df .drop ("direction" , axis = 1 , inplace = True )
237- api_df ["data_source" ] = data_source
238- api_df ["signal" ] = signal
239-
240- return api_df
241-
242-
243157def generate_start_date_per_signal () -> Dict [Tuple [datetime , datetime , str ], List [Tuple [str ]]]:
244158 """
245159 Generate a dictionary of date range associated with individual signals
0 commit comments