diff --git a/_delphi_utils_python/.pylintrc b/_delphi_utils_python/.pylintrc index 2a9334425..994d47417 100644 --- a/_delphi_utils_python/.pylintrc +++ b/_delphi_utils_python/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/_template_python/.pylintrc b/_template_python/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/_template_python/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/cdc_covidnet/.pylintrc b/cdc_covidnet/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/cdc_covidnet/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/changehc/.pylintrc b/changehc/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/changehc/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/claims_hosp/.pylintrc b/claims_hosp/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/claims_hosp/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/combo_cases_and_deaths/.pylintrc b/combo_cases_and_deaths/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/combo_cases_and_deaths/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/emr_hosp/.pylintrc b/emr_hosp/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/emr_hosp/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/google_health/.pylintrc b/google_health/.pylintrc index 2a9334425..994d47417 100644 --- a/google_health/.pylintrc +++ b/google_health/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/google_health/delphi_google_health/pull_api.py b/google_health/delphi_google_health/pull_api.py index faa3734d5..868e8975d 100644 --- a/google_health/delphi_google_health/pull_api.py +++ b/google_health/delphi_google_health/pull_api.py @@ -77,7 +77,7 @@ def query(self, start_date: str, end_date: str, geo_id, dma=False) -> dict: start_date, end_date, ) - data = self.service.getTimelinesForHealth(**params).execute() + data = self.service.getTimelinesForHealth(**params).execute() #pylint: disable=no-member return data diff --git a/google_health/delphi_google_health/smooth.py b/google_health/delphi_google_health/smooth.py index e34484ecf..d8195ab34 100644 --- a/google_health/delphi_google_health/smooth.py +++ b/google_health/delphi_google_health/smooth.py @@ -60,11 +60,12 @@ def _left_gauss_linear(s: np.ndarray, h=10, impute=False, minval=None) -> np.nda n = len(s) t = np.zeros_like(s, dtype=np.float64) - X = np.vstack([np.ones(n), np.arange(n)]).T + X = np.vstack([np.ones(n), np.arange(n)]).T #pylint: disable=invalid-name for idx in range(n): wts = np.exp(-((np.arange(idx + 1) - idx) ** 2) / (h ** 2)) - XwX = np.dot(X[: (idx + 1), :].T * wts, X[: (idx + 1), :]) - Xwy = np.dot(X[: (idx + 1), :].T * wts, s[: (idx + 1)].reshape(-1, 1)) + XwX = np.dot(X[: (idx + 1), :].T * wts, X[: (idx + 1), :]) #pylint: disable=invalid-name + Xwy = np.dot(X[: (idx + 1), :].T * wts, #pylint: disable=invalid-name + s[: (idx + 1)].reshape(-1, 1)) try: beta = np.linalg.solve(XwX, Xwy) t[idx] = np.dot(X[: (idx + 1), :], beta)[-1] diff --git a/jhu/.pylintrc b/jhu/.pylintrc index 2a9334425..994d47417 100644 --- a/jhu/.pylintrc +++ b/jhu/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/jhu/delphi_jhu/geo.py b/jhu/delphi_jhu/geo.py index ea79babb1..1e76c491b 100644 --- a/jhu/delphi_jhu/geo.py +++ b/jhu/delphi_jhu/geo.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- +"""Functions for translating between geocodes.""" import pandas as pd from delphi_utils import GeoMapper +VALID_GEO_RES = ("county", "state", "msa", "hrr") INCIDENCE_BASE = 100000 def geo_map(df: pd.DataFrame, geo_res: str): @@ -27,7 +29,6 @@ def geo_map(df: pd.DataFrame, geo_res: str): Columns: geo_id, timestamp, ... """ df = df.copy() - VALID_GEO_RES = ("county", "state", "msa", "hrr") if geo_res not in VALID_GEO_RES: raise ValueError(f"geo_res must be one of {VALID_GEO_RES}") diff --git a/jhu/delphi_jhu/pull.py b/jhu/delphi_jhu/pull.py index 3b5ddbe6f..95b74f1da 100644 --- a/jhu/delphi_jhu/pull.py +++ b/jhu/delphi_jhu/pull.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Functions to pull data from JHU website.""" import pandas as pd import numpy as np diff --git a/jhu/delphi_jhu/run.py b/jhu/delphi_jhu/run.py index ee9d1c85b..8f8067da3 100644 --- a/jhu/delphi_jhu/run.py +++ b/jhu/delphi_jhu/run.py @@ -66,7 +66,7 @@ def run_module(): - + """Run the JHU indicator module.""" params = read_params() export_start_date = params["export_start_date"] export_dir = params["export_dir"] diff --git a/jhu/delphi_jhu/smooth.py b/jhu/delphi_jhu/smooth.py index a6c944fc2..5c9e18a3f 100644 --- a/jhu/delphi_jhu/smooth.py +++ b/jhu/delphi_jhu/smooth.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +'''Functions to smooth signals.''' + import numpy as np def identity(x): diff --git a/nchs_mortality/.pylintrc b/nchs_mortality/.pylintrc index 2a9334425..994d47417 100644 --- a/nchs_mortality/.pylintrc +++ b/nchs_mortality/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/quidel/.pylintrc b/quidel/.pylintrc new file mode 100644 index 000000000..994d47417 --- /dev/null +++ b/quidel/.pylintrc @@ -0,0 +1,21 @@ + +[MESSAGES CONTROL] + +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods + +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] + +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/quidel_covidtest/.pylintrc b/quidel_covidtest/.pylintrc index 2a9334425..994d47417 100644 --- a/quidel_covidtest/.pylintrc +++ b/quidel_covidtest/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/quidel_covidtest/delphi_quidel_covidtest/generate_sensor.py b/quidel_covidtest/delphi_quidel_covidtest/generate_sensor.py index caa8deece..eb8a7cff7 100644 --- a/quidel_covidtest/delphi_quidel_covidtest/generate_sensor.py +++ b/quidel_covidtest/delphi_quidel_covidtest/generate_sensor.py @@ -93,7 +93,7 @@ def generate_sensor_for_other_geores(state_groups, data, res_key, smooth, res_group = res_group.merge(parent_group, how="left", on="timestamp", suffixes=('', '_parent')) res_group = res_group.drop(columns=[res_key, "state_id", "state_id" + '_parent']) - except: + except KeyError: has_parent = False res_group = res_group.drop(columns=[res_key, "state_id"]) res_group.set_index("timestamp", inplace=True) diff --git a/quidel_covidtest/delphi_quidel_covidtest/pull.py b/quidel_covidtest/delphi_quidel_covidtest/pull.py index c19ddabb5..d98b7caa1 100644 --- a/quidel_covidtest/delphi_quidel_covidtest/pull.py +++ b/quidel_covidtest/delphi_quidel_covidtest/pull.py @@ -193,9 +193,9 @@ def pull_quidel_covidtest(params): Parameters: params: dict including all the information read from params.json - END_FROM_TODAY_MINUS: int + end_from_today_minus: int report data until - X days - EXPORT_DAY_RANGE: int + export_day_range: int number of dates to report Returns: @@ -238,11 +238,11 @@ def pull_quidel_covidtest(params): return df, _end_date def check_export_end_date(input_export_end_date, _end_date, - END_FROM_TODAY_MINUS): + end_from_today_minus): """ Update the export_end_date according to the data received By default, set the export end date to be the last pulling date - 5 days - (END_FROM_TODAY_MINUS = 5). + (end_from_today_minus = 5). Otherwise, use the required date if it is earlier than the default one. Parameter: @@ -250,14 +250,14 @@ def check_export_end_date(input_export_end_date, _end_date, read from params _end_date: datetime.datetime updated according the data received - END_FROM_TODAY_MINUS: int + end_from_today_minus: int report data until - X days Returns: datetime.datetime export data from which date """ - export_end_date = _end_date - timedelta(days=END_FROM_TODAY_MINUS) + export_end_date = _end_date - timedelta(days=end_from_today_minus) if input_export_end_date != "": input_export_end_date = datetime.strptime(input_export_end_date, '%Y-%m-%d') if input_export_end_date < export_end_date: @@ -265,17 +265,17 @@ def check_export_end_date(input_export_end_date, _end_date, return export_end_date def check_export_start_date(export_start_date, export_end_date, - EXPORT_DAY_RANGE): + export_day_range): """ Update the export_start_date according to the export_end_date so that it - could be export_end_date - EXPORT_DAY_RANGE + could be export_end_date - export_day_range Parameters: export_start_date: str Read from params export_end_date: datetime.datetime Calculated according to the data received - EXPORT_DAY_RANGE: int + export_day_range: int Number of days to report Returns: @@ -287,8 +287,8 @@ def check_export_start_date(export_start_date, export_end_date, else: export_start_date = datetime.strptime(export_start_date, '%Y-%m-%d') # Only export data from -45 days to -5 days - if (export_end_date - export_start_date).days > EXPORT_DAY_RANGE: - export_start_date = export_end_date - timedelta(days=EXPORT_DAY_RANGE) + if (export_end_date - export_start_date).days > export_day_range: + export_start_date = export_end_date - timedelta(days=export_day_range) if export_start_date < datetime(2020, 5, 26): return datetime(2020, 5, 26) diff --git a/quidel_covidtest/delphi_quidel_covidtest/run.py b/quidel_covidtest/delphi_quidel_covidtest/run.py index 0c596bd08..2687322b7 100644 --- a/quidel_covidtest/delphi_quidel_covidtest/run.py +++ b/quidel_covidtest/delphi_quidel_covidtest/run.py @@ -25,6 +25,7 @@ def run_module(): + """Run the quidel_covidtest indicator.""" params = read_params() cache_dir = params["cache_dir"] export_dir = params["export_dir"] diff --git a/quidel_covidtest/tests/cache/.gitignore b/quidel_covidtest/tests/cache/.gitignore new file mode 100644 index 000000000..afed0735d --- /dev/null +++ b/quidel_covidtest/tests/cache/.gitignore @@ -0,0 +1 @@ +*.csv diff --git a/safegraph/.pylintrc b/safegraph/.pylintrc index 2a9334425..994d47417 100644 --- a/safegraph/.pylintrc +++ b/safegraph/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/safegraph_patterns/.pylintrc b/safegraph_patterns/.pylintrc index 2a9334425..994d47417 100644 --- a/safegraph_patterns/.pylintrc +++ b/safegraph_patterns/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/usafacts/.pylintrc b/usafacts/.pylintrc index 2a9334425..994d47417 100644 --- a/usafacts/.pylintrc +++ b/usafacts/.pylintrc @@ -1,8 +1,21 @@ -[DESIGN] -min-public-methods=1 +[MESSAGES CONTROL] +disable=logging-format-interpolation, + too-many-locals, + too-many-arguments, + # Allow pytest functions to be part of a class. + no-self-use, + # Allow pytest classes to have one test. + too-few-public-methods -[MESSAGES CONTROL] +[BASIC] + +# Allow arbitrarily short-named variables. +variable-rgx=[a-z_][a-z0-9_]* +argument-rgx=[a-z_][a-z0-9_]* + +[DESIGN] -disable=R0801, C0330, E1101, E0611, C0114, C0116, C0103, R0913, R0914, W0702 +# Don't complain about pytest "unused" arguments. +ignored-argument-names=(_.*|run_as_module) \ No newline at end of file diff --git a/usafacts/delphi_usafacts/geo.py b/usafacts/delphi_usafacts/geo.py index ff9b50f6c..fd6284976 100644 --- a/usafacts/delphi_usafacts/geo.py +++ b/usafacts/delphi_usafacts/geo.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Functions for converting geocodes.""" import pandas as pd @@ -78,6 +79,11 @@ FIPS_TO_STATE = {v: k.lower() for k, v in STATE_TO_FIPS.items()} +# Valid geographical resolutions output by this indicator. +VALID_GEO_RES = ("county", "state", "msa", "hrr") +# Sensors that report proportions. For geo resolutions with unallocated cases +# or deaths, we avoid reporting these sensors. +PROP_SENSORS = ("incidence", "cumulative_prop") def fips_to_state(fips: str) -> str: """Wrapper that handles exceptions to the FIPS scheme in the USAFacts data. @@ -121,9 +127,9 @@ def disburse(df: pd.DataFrame, pooled_fips: str, fips_list: list): pd.DataFrame Dataframe with same schema as df, with the counts disbursed. """ - COLS = ["new_counts", "cumulative_counts"] + cols = ["new_counts", "cumulative_counts"] df = df.copy().sort_values(["fips", "timestamp"]) - for col in COLS: + for col in cols: # Get values from the aggregated county: vals = df.loc[df["fips"] == pooled_fips, col].values / len(fips_list) for fips in fips_list: @@ -155,9 +161,6 @@ def geo_map(df: pd.DataFrame, geo_res: str, map_df: pd.DataFrame, sensor: str): pd.DataFrame Columns: geo_id, timestamp, ... """ - VALID_GEO_RES = ("county", "state", "msa", "hrr") - #It is not clear how to calculate the proportion for unallocated cases/deaths - PROP_SENSORS = ("incidence", "cumulative_prop") if geo_res not in VALID_GEO_RES: raise ValueError(f"geo_res must be one of {VALID_GEO_RES}") diff --git a/usafacts/delphi_usafacts/pull.py b/usafacts/delphi_usafacts/pull.py index f8278b344..220ff2502 100644 --- a/usafacts/delphi_usafacts/pull.py +++ b/usafacts/delphi_usafacts/pull.py @@ -1,7 +1,16 @@ # -*- coding: utf-8 -*- +"""Functions for pulling data from the USAFacts website.""" import numpy as np import pandas as pd +# Columns to drop the the data frame. +DROP_COLUMNS = [ + "FIPS", + "County Name", + "State", + "stateFIPS" +] + def pull_usafacts_data(base_url: str, metric: str, pop_df: pd.DataFrame) -> pd.DataFrame: """Pulls the latest USA Facts data, and conforms it into a dataset @@ -43,15 +52,6 @@ def pull_usafacts_data(base_url: str, metric: str, pop_df: pd.DataFrame) -> pd.D pd.DataFrame Dataframe as described above. """ - # Constants - DROP_COLUMNS = [ - "FIPS", - "County Name", - "State", - "stateFIPS" - ] - # MIN_FIPS = 1000 - # MAX_FIPS = 57000 # Read data df = pd.read_csv(base_url.format(metric=metric)).rename({"countyFIPS":"FIPS"}, axis=1) @@ -59,8 +59,8 @@ def pull_usafacts_data(base_url: str, metric: str, pop_df: pd.DataFrame) -> pd.D null_mask = pd.isnull(df["FIPS"]) assert null_mask.sum() == 0 - UNEXPECTED_COLUMNS = [x for x in df.columns if "Unnamed" in x] - DROP_COLUMNS.extend(UNEXPECTED_COLUMNS) + unexpected_columns = [x for x in df.columns if "Unnamed" in x] + unexpected_columns.extend(DROP_COLUMNS) # Assign Grand Princess Cruise Ship a special FIPS 90000 # df.loc[df["FIPS"] == 6000, "FIPS"] = 90000 @@ -90,7 +90,7 @@ def pull_usafacts_data(base_url: str, metric: str, pop_df: pd.DataFrame) -> pd.D "Tried to drop non-existent columns. The dataset " "schema may have changed. Please investigate and " "amend DROP_COLUMNS." - ) + ) from e # Check that columns are either FIPS or dates try: columns = list(df.columns) @@ -99,13 +99,12 @@ def pull_usafacts_data(base_url: str, metric: str, pop_df: pd.DataFrame) -> pd.D # Detects whether there is a non-date string column -- not perfect _ = [int(x.replace("/", "")) for x in columns] except ValueError as e: - print(e) raise ValueError( "Detected unexpected column(s) " "after dropping DROP_COLUMNS. The dataset " "schema may have changed. Please investigate and " "amend DROP_COLUMNS." - ) + ) from e # Reshape dataframe df = df.melt( id_vars=["fips", "population"], diff --git a/usafacts/delphi_usafacts/run.py b/usafacts/delphi_usafacts/run.py index a75a8b2b7..ea3fc8d6b 100644 --- a/usafacts/delphi_usafacts/run.py +++ b/usafacts/delphi_usafacts/run.py @@ -67,7 +67,7 @@ def run_module(): - + """Run the usafacts indicator.""" params = read_params() export_start_date = params["export_start_date"] if export_start_date == "latest": diff --git a/usafacts/delphi_usafacts/smooth.py b/usafacts/delphi_usafacts/smooth.py index a6c944fc2..86051fdf2 100644 --- a/usafacts/delphi_usafacts/smooth.py +++ b/usafacts/delphi_usafacts/smooth.py @@ -1,3 +1,4 @@ +'''Functions for smoothing signals.''' # -*- coding: utf-8 -*- import numpy as np