Skip to content

Commit be5f9dc

Browse files
committed
Merge conflicts.
2 parents 86a3dad + 062a642 commit be5f9dc

File tree

196 files changed

+14043
-1208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+14043
-1208
lines changed

.github/workflows/r_ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
#
6+
# See https://github.com/r-lib/actions/tree/master/examples#readme for
7+
# additional example workflows available for the R community.
8+
9+
name: R
10+
11+
on:
12+
push:
13+
branches: [ main ]
14+
pull_request:
15+
branches: [ main ]
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
defaults:
21+
run:
22+
working-directory: R-packages/covidcast/
23+
strategy:
24+
matrix:
25+
r-version: [3.5]
26+
27+
steps:
28+
- uses: actions/checkout@v2
29+
- name: Set up R ${{ matrix.r-version }}
30+
uses: r-lib/actions/setup-r@ffe45a39586f073cc2e9af79c4ba563b657dc6e3
31+
with:
32+
r-version: ${{ matrix.r-version }}
33+
- name: Install linux dependencies
34+
run: |
35+
sudo apt-get install libcurl4-openssl-dev
36+
sudo apt-get install libudunits2-dev
37+
sudo apt-get install libgdal-dev
38+
- name: Cache R packages
39+
uses: actions/cache@v2
40+
with:
41+
path: ${{ env.R_LIBS_USER }}
42+
key: ${{ runner.os }}-r-1-
43+
- name: Install dependencies
44+
run: |
45+
install.packages(c("remotes", "rcmdcheck"))
46+
remotes::install_deps(dependencies = TRUE)
47+
shell: Rscript {0}
48+
- name: Check
49+
run: |
50+
rcmdcheck::rcmdcheck(args = c("--no-manual", "--ignore-vignettes", "--as-cran"), build_args = c("--no-build-vignettes"), error_on = "error")
51+
shell: Rscript {0}

Python-packages/covidcast-py/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.PHONY = lint, test, install-requirements, build-and-install
22

33
install-requirements:
4-
pip install -r requirements_ci.txt
54
pip install -r requirements_dev.txt
5+
pip install -r requirements_ci.txt
66

77
build-and-install: install-requirements
88
python3 setup.py clean
236 KB
Loading

Python-packages/covidcast-py/covidcast/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
from .covidcast import signal, metadata, aggregate_signals
1616
from .plotting import plot, plot_choropleth, get_geo_df, animate
1717
from .geography import (fips_to_name, cbsa_to_name, abbr_to_name,
18-
name_to_abbr, name_to_cbsa, name_to_fips)
18+
name_to_abbr, name_to_cbsa, name_to_fips,
19+
fips_to_abbr, abbr_to_fips)

Python-packages/covidcast-py/covidcast/covidcast.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""This is the client side library for accessing the COVIDcast API."""
22
import warnings
33
from datetime import timedelta, date
4-
from typing import Union, Iterable, Tuple, List
54
from functools import reduce
5+
from typing import Union, Iterable, Tuple, List
66

77
import pandas as pd
88
from delphi_epidata import Epidata
99

10+
from .errors import NoDataWarning
11+
1012
# Point API requests to the AWS endpoint
1113
Epidata.BASE_URL = "https://api.covidcast.cmu.edu/epidata/api.php"
1214

@@ -211,21 +213,21 @@ def metadata() -> pd.DataFrame:
211213
``signal``
212214
Signal name.
213215
214-
``min_time``
215-
First day for which this signal is available.
216-
217-
``max_time``
218-
Most recent day for which this signal is available.
216+
``time_type``
217+
Temporal resolution at which this signal is reported. "day", for
218+
example, means the signal is reported daily.
219219
220220
``geo_type``
221221
Geographic level for which this signal is available, such as county,
222222
state, msa, or hrr. Most signals are available at multiple geographic
223223
levels and will hence be listed in multiple rows with their own
224224
metadata.
225225
226-
``time_type``
227-
Temporal resolution at which this signal is reported. "day", for
228-
example, means the signal is reported daily.
226+
``min_time``
227+
First day for which this signal is available.
228+
229+
``max_time``
230+
Most recent day for which this signal is available.
229231
230232
``num_locations``
231233
Number of distinct geographic locations available for this signal. For
@@ -244,6 +246,17 @@ def metadata() -> pd.DataFrame:
244246
``stdev_value``
245247
The sample standard deviation of all reported values.
246248
249+
``last_update``
250+
The UTC datetime for when the signal value was last updated.
251+
252+
``max_issue``
253+
Most recent date data was issued.
254+
255+
``min_lag``
256+
Smallest lag from observation to issue, in days.
257+
258+
``max_lag``
259+
Largest lag from observation to issue, in days.
247260
"""
248261
meta = Epidata.covidcast_meta()
249262

@@ -255,7 +268,7 @@ def metadata() -> pd.DataFrame:
255268
meta_df = pd.DataFrame.from_dict(meta["epidata"])
256269
meta_df["min_time"] = pd.to_datetime(meta_df["min_time"], format="%Y%m%d")
257270
meta_df["max_time"] = pd.to_datetime(meta_df["max_time"], format="%Y%m%d")
258-
271+
meta_df["last_update"] = pd.to_datetime(meta_df["last_update"], unit="s")
259272
return meta_df
260273

261274

@@ -372,10 +385,14 @@ def _fetch_single_geo(data_source: str,
372385
issues=issues_strs, lag=lag)
373386

374387
# Two possible error conditions: no data or too much data.
375-
if day_data["message"] != "success":
376-
warnings.warn("Problem obtaining data on {day}: {message}".format(
377-
day=day_str,
378-
message=day_data["message"]))
388+
if day_data["message"] == "no results":
389+
warnings.warn(f"No {data_source} {signal} data found on {day_str} "
390+
f"for geography '{geo_type}'",
391+
NoDataWarning)
392+
if day_data["message"] not in {"success", "no results"}:
393+
warnings.warn(f"Problem obtaining {data_source} {signal} data on {day_str} "
394+
f"for geography '{geo_type}': {day_data['message']}",
395+
RuntimeWarning)
379396

380397
# In the too-much-data case, we continue to try putting the truncated
381398
# data in our results. In the no-data case, skip this day entirely,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Custom warnings and exceptions for covidcast functions."""
2+
3+
4+
class NoDataWarning(Warning):
5+
"""Warning raised when no data is returned on a given day by covidcast.signal()."""

Python-packages/covidcast-py/covidcast/geography.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
# Filter undesired rows from CSVs.
1717
# They're not removed from the files to keep them identical to rda files.
1818
STATE_CENSUS = STATE_CENSUS.loc[STATE_CENSUS.STATE != "0"]
19+
# pad to 2 characters with leading 0s
20+
STATE_CENSUS["STATE"] = STATE_CENSUS["STATE"].str.zfill(2)
21+
# add 000 to the end to get a 5 digit code
22+
STATE_CENSUS["STATE"] = STATE_CENSUS["STATE"].str.pad(width=5, fillchar="0", side="right")
23+
# filter out micropolitan areas
1924
MSA_CENSUS = MSA_CENSUS.loc[MSA_CENSUS.LSAD == "Metropolitan Statistical Area"]
2025

2126

@@ -128,6 +133,34 @@ def name_to_abbr(name: Union[str, Iterable],
128133
return _lookup(name, STATE_CENSUS.NAME, STATE_CENSUS.ABBR, ignore_case, fixed, ties_method)
129134

130135

136+
def fips_to_abbr(code: Union[str, Iterable],
137+
ignore_case: bool = False,
138+
fixed: bool = False,
139+
ties_method: str = "first") -> list:
140+
"""Look up state abbreviation by FIPS codes with regular expression support.
141+
142+
Given an individual or list of FIPS codes or regular expressions, look up the corresponding
143+
state abbreviation. FIPS codes can be the 2 digit code (``covidcast.fips_to_abbr("12")``) or
144+
the 2 digit code with 000 appended to the end (``covidcast.fips_to_abbr("12000")``.
145+
146+
:param code: Individual or list of FIPS codes or regular expressions.
147+
:param ignore_case: Boolean for whether or not to be case insensitive in the regular expression.
148+
If ``fixed=True``, this argument is ignored. Defaults to ``False``.
149+
:param fixed: Conduct an exact case sensitive match with the input string.
150+
Defaults to ``False``.
151+
:param ties_method: Method for determining how to deal with multiple outputs for a given input.
152+
Must be one of ``"all"`` or ``"first"``. If ``"first"``, then only the first match for each
153+
code is returned. If ``"all"``, then all matches for each code are returned.
154+
Defaults to ``first``.
155+
:return: If ``ties_method="first"``, returns a list of the first value found for each input key.
156+
If ``ties_method="all"``, returns a list of dicts, one for each input, with keys
157+
corresponding to all matched input keys and values corresponding to the list of county names.
158+
The returned list will be the same length as the input, with ``None`` or ``{}`` if no values
159+
are found for ``ties_method="first"`` and ``ties_method="all"``, respectively.
160+
"""
161+
return _lookup(code, STATE_CENSUS.STATE, STATE_CENSUS.ABBR, ignore_case, fixed, ties_method)
162+
163+
131164
def name_to_cbsa(name: Union[str, Iterable],
132165
ignore_case: bool = False,
133166
fixed: bool = False,
@@ -162,6 +195,34 @@ def name_to_cbsa(name: Union[str, Iterable],
162195
return _lookup(name, df.NAME, df.CBSA, ignore_case, fixed, ties_method)
163196

164197

198+
def abbr_to_fips(code: Union[str, Iterable],
199+
ignore_case: bool = False,
200+
fixed: bool = False,
201+
ties_method: str = "first") -> list:
202+
"""Look up state FIPS codes by abbreviation with regular expression support.
203+
204+
Given an individual or list of state abbreviations or regular expressions,
205+
look up the corresponding state FIPS codes. The returned codes are 5 digits: the
206+
2 digit state FIPS with 000 appended to the end.
207+
208+
:param code: Individual or list of abbreviations or regular expressions.
209+
:param ignore_case: Boolean for whether or not to be case insensitive in the regular expression.
210+
If ``fixed=True``, this argument is ignored. Defaults to ``False``.
211+
:param fixed: Conduct an exact case sensitive match with the input string.
212+
Defaults to ``False``.
213+
:param ties_method: Method for determining how to deal with multiple outputs for a given input.
214+
Must be one of ``"all"`` or ``"first"``. If ``"first"``, then only the first match for each
215+
code is returned. If ``"all"``, then all matches for each code are returned.
216+
Defaults to ``first``.
217+
:return: If ``ties_method="first"``, returns a list of the first value found for each input key.
218+
If ``ties_method="all"``, returns a list of dicts, one for each input, with keys
219+
corresponding to all matched input keys and values corresponding to the list of county names.
220+
The returned list will be the same length as the input, with ``None`` or ``{}`` if no values
221+
are found for ``ties_method="first"`` and ``ties_method="all"``, respectively.
222+
"""
223+
return _lookup(code, STATE_CENSUS.ABBR, STATE_CENSUS.STATE, ignore_case, fixed, ties_method)
224+
225+
165226
def name_to_fips(name: Union[str, Iterable],
166227
ignore_case: bool = False,
167228
fixed: bool = False,

0 commit comments

Comments
 (0)