Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
more lint
  • Loading branch information
aysim319 committed Jul 8, 2024
1 parent 81381d6 commit 167d75c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
44 changes: 26 additions & 18 deletions doctor_visits/delphi_doctor_visits/process_data.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import dask.dataframe as dd
"""Module providing functions for processing and wrangling data."""

from datetime import datetime
from pathlib import Path

import numpy as np
import pandas as pd
from pathlib import Path

import dask.dataframe as dd
from .config import Config

def format_outname(prefix: str, se: bool, weekday:bool):
'''
"""
Write out results.
Parameters
----------
prefix
se
weekday
prefix:
se: boolean to write out standard errors, if true, use an obfuscated name
weekday: boolean for weekday adjustments.
signals will be generated with weekday adjustments (True) or without
adjustments (False)
Returns
-------
'''
# write out results
outname str
"""
out_name = "smoothed_adj_cli" if weekday else "smoothed_cli"
if se:
assert prefix is not None, "template has no obfuscated prefix"
out_name = prefix + "_" + out_name
return out_name

def format_df(df: pd.DataFrame, geo_id: str, se: bool, logger):
'''
format dataframe and checks for anomalies to write results
"""
Format dataframe and checks for anomalies to write results.
Parameters
----------
df: dataframe from output from update_sensor
Expand All @@ -39,7 +45,7 @@ def format_df(df: pd.DataFrame, geo_id: str, se: bool, logger):
Returns
-------
filtered and formatted dataframe
'''
"""
# report in percentage
df['val'] = df['val'] * 100
df["se"] = df["se"] * 100
Expand All @@ -66,7 +72,7 @@ def format_df(df: pd.DataFrame, geo_id: str, se: bool, logger):
valid_cond = (df['se'] > 0) & (df['val'] > 0)
invalid_df = df[~valid_cond]
if len(invalid_df) > 0:
logger.info(f"p=0, std_err=0 invalid")
logger.info("p=0, std_err=0 invalid")
df = df[valid_cond]
else:
df["se"] = np.NAN
Expand All @@ -76,7 +82,8 @@ def format_df(df: pd.DataFrame, geo_id: str, se: bool, logger):
return df

def write_to_csv(output_df: pd.DataFrame, prefix: str, geo_id: str, weekday: bool, se:bool, logger, output_path="."):
"""Write sensor values to csv.
"""
Write sensor values to csv.
Args:
output_dict: dictionary containing sensor rates, se, unique dates, and unique geo_id
Expand Down Expand Up @@ -106,9 +113,10 @@ def write_to_csv(output_df: pd.DataFrame, prefix: str, geo_id: str, weekday: boo


def csv_to_df(filepath: str, startdate: datetime, enddate: datetime, dropdate: datetime, logger) -> pd.DataFrame:
'''
Reads csv using Dask and filters out based on date range and currently unused column,
then converts back into pandas dataframe.
"""
Read csv using Dask and filters out based on date range and currently unused column.
Then converts back into pandas dataframe.
Parameters
----------
filepath: path to the aggregated doctor-visits data
Expand All @@ -117,7 +125,7 @@ def csv_to_df(filepath: str, startdate: datetime, enddate: datetime, dropdate: d
dropdate: data drop date (YYYY-mm-dd)
-------
'''
"""
filepath = Path(filepath)
logger.info(f"Processing {filepath}")

Expand Down
2 changes: 0 additions & 2 deletions doctor_visits/delphi_doctor_visits/update_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- 2020-04-30: Aaron Rumack (add megacounty code)
- 2020-05-06: Aaron and Maria (weekday effects/other adjustments)
"""

# standard packages
from datetime import timedelta, datetime
from multiprocessing import Pool, cpu_count
Expand Down Expand Up @@ -41,7 +40,6 @@ def update_sensor(
se: boolean to write out standard errors, if true, use an obfuscated name
logger: the structured logger
"""

drange = lambda s, e: np.array([s + timedelta(days=x) for x in range((e - s).days)])
fit_dates = drange(Config.FIRST_DATA_DATE, dropdate)
burnindate = startdate - Config.DAY_SHIFT
Expand Down

0 comments on commit 167d75c

Please sign in to comment.