Skip to content

Update cdccovidnet docstrings to pass pydocstyle #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cdc_covidnet/delphi_cdc_covidnet/api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"""

class APIConfig:
"""
Static configuration variables
"""
"""Static configuration variables."""

# API Parameters
INIT_URL = "https://gis.cdc.gov/grasp/covid19_3_api/GetPhase03InitApp"
MMWR_COLS = ["year", "weeknumber", "weekstart", "weekend"]
Expand Down
4 changes: 1 addition & 3 deletions cdc_covidnet/delphi_cdc_covidnet/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""
Registry for signal names
"""
"""Registry for signal names."""
COVIDNET = "covidnet"
SIGNALS = [COVIDNET]
21 changes: 7 additions & 14 deletions cdc_covidnet/delphi_cdc_covidnet/covidnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@
from .api_config import APIConfig

class CovidNet:
"""
Methods for downloading and loading COVID-NET data
"""
"""Methods for downloading and loading COVID-NET data."""

@staticmethod
def download_mappings(
url: str = APIConfig.INIT_URL,
outfile: str = "./init.json"):
"""
Downloads the JSON file with all mappings (age, mmwr, catchments etc.) to disk
Download the JSON file with all mappings (age, mmwr, catchments etc.) to disk.

Args:
url: The API URL to GET from
outfile: The output JSON file to write to
"""

params = {"appVersion": "Public"}
data = requests.get(url, params).json()
with open(outfile, "w") as f_json:
Expand All @@ -41,8 +38,7 @@ def download_mappings(
@staticmethod
def read_mappings(infile: str) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
"""
Reads the mappings JSON file from disk to produce formatted
pd.DataFrame for relevant mappings
Read the mappings JSON file from disk to produce formatted DataFrames for relevant mappings.

Args:
infile: Mappings JSON file
Expand All @@ -52,7 +48,6 @@ def read_mappings(infile: str) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame
mmwr_info: Date-related mappings
catchment_info: Geography-related mappings
"""

with open(infile, "r") as f_json:
data = json.load(f_json)

Expand All @@ -76,7 +71,8 @@ def download_hosp_data(
outfile: str,
url: str = APIConfig.HOSP_URL):
"""
Downloads hospitalization data to disk for a particular network or state
Download hospitalization data to disk for a particular network or state.

Refer to catchment_info for network & catchment ID mappings
Refer to age_info for age-group mappings
Seasons are enumerated in original mappings JSON file
Expand All @@ -89,7 +85,6 @@ def download_hosp_data(
outfile: JSON file to write the results to
url: The API URL to POST to for downloading hospitalization data
"""

download_params = {
"AppVersion": "Public",
"networkid": network_id,
Expand All @@ -108,7 +103,7 @@ def download_all_hosp_data(
mappings_file: str, cache_path: str, parallel: bool = False
) -> List[str]:
"""
Downloads hospitalization data for all states listed in the mappings JSON file to disk.
Download hospitalization data for all states listed in the mappings JSON file to disk.

Args:
mappings_file: Mappings JSON file
Expand All @@ -118,7 +113,6 @@ def download_all_hosp_data(
Returns:
List of all downloaded JSON filenames (including the cache_path)
"""

catchment_info, _, age_info = CovidNet.read_mappings(mappings_file)

# By state
Expand Down Expand Up @@ -159,15 +153,14 @@ def download_all_hosp_data(
@staticmethod
def read_all_hosp_data(state_files: List[str]) -> pd.DataFrame:
"""
Read and combine hospitalization JSON files for each state into a pd.DataFrame
Read and combine hospitalization JSON files for each state into a pd.DataFrame.

Args:
state_files: List of hospitalization JSON files for each state to read from disk

Returns:
Single pd.DataFrame with all the hospitalization data combined
"""

dfs = []
for state_file in state_files:
# Read json
Expand Down
5 changes: 1 addition & 4 deletions cdc_covidnet/delphi_cdc_covidnet/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@


def run_module():
"""
Parse parameters and generates csv files for the COVID-NET sensor
"""

"""Parse parameters and generates csv files for the COVID-NET sensor."""
params = read_params()

logging.basicConfig(level=logging.DEBUG)
Expand Down
9 changes: 5 additions & 4 deletions cdc_covidnet/delphi_cdc_covidnet/update_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
def write_to_csv(data: pd.DataFrame, out_name: str, output_path: str):
"""
Write sensor values to csv.

The dataframe be indexed by (date, geo_id), with columns
values, se, sample_size

Expand All @@ -29,7 +30,6 @@ def write_to_csv(data: pd.DataFrame, out_name: str, output_path: str):
output_name: Suffix name to add to each output file
output_path: Path to write the csvs to
"""

# Each date is a csv file
dates = data.index.get_level_values("date").unique()
for date in dates:
Expand Down Expand Up @@ -109,7 +109,8 @@ def update_sensor(


def add_prefix(signal_names, wip_signal, prefix):
"""Adds prefix to signal if there is a WIP signal
"""Add prefix to signal if there is a WIP signal.

Parameters
----------
signal_names: List[str]
Expand All @@ -125,7 +126,6 @@ def add_prefix(signal_names, wip_signal, prefix):
List of signal names
wip/non wip signals for further computation
"""

if wip_signal is True:
return [prefix + signal for signal in signal_names]
if isinstance(wip_signal, list):
Expand All @@ -144,7 +144,8 @@ def add_prefix(signal_names, wip_signal, prefix):


def public_signal(signal_):
"""Checks if the signal name is already public using COVIDcast
"""Check if the signal name is already public using COVIDcast.

Parameters
----------
signal_ : str
Expand Down