From afa65694d46df1065dd84c28304f23acc2c1a098 Mon Sep 17 00:00:00 2001 From: andrew Date: Fri, 6 Nov 2020 12:45:16 -0800 Subject: [PATCH 1/3] fix linting --- nchs_mortality/delphi_nchs_mortality/pull.py | 26 ++++++++++---------- nchs_mortality/delphi_nchs_mortality/run.py | 10 ++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/nchs_mortality/delphi_nchs_mortality/pull.py b/nchs_mortality/delphi_nchs_mortality/pull.py index 73aa64810..08358badd 100644 --- a/nchs_mortality/delphi_nchs_mortality/pull.py +++ b/nchs_mortality/delphi_nchs_mortality/pull.py @@ -33,12 +33,12 @@ def pull_nchs_mortality_data(token: str, map_df: pd.DataFrame, test_mode: str): Dataframe as described above. """ # Constants - KEEP_COLUMNS = ['covid_deaths', 'total_deaths', + keep_columns = ['covid_deaths', 'total_deaths', 'percent_of_expected_deaths', 'pneumonia_deaths', 'pneumonia_and_covid_deaths', 'influenza_deaths', 'pneumonia_influenza_or_covid_19_deaths'] - TYPE_DICT = {key: float for key in KEEP_COLUMNS} - TYPE_DICT["timestamp"] = 'datetime64[ns]' + type_dict = {key: float for key in keep_columns} + type_dict["timestamp"] = 'datetime64[ns]' if test_mode == "": # Pull data from Socrata API @@ -52,18 +52,18 @@ def pull_nchs_mortality_data(token: str, map_df: pd.DataFrame, test_mode: str): # Check missing start_week == end_week try: assert sum(df["timestamp"] != df["end_week"]) == 0 - except AssertionError: + except AssertionError as exc: raise ValueError( "end_week is not always the same as start_week, check the raw file" - ) + ) from exc try: - df = df.astype(TYPE_DICT) - except KeyError: + df = df.astype(type_dict) + except KeyError as exc: raise ValueError("Expected column(s) missed, The dataset " - "schema may have changed. Please investigate and " - "amend the code.") - + "schema may have changed. Please investigate and " + "amend the code.") from exc + df = df[df["state"] != "United States"] df.loc[df["state"] == "New York City", "state"] = "New York" @@ -91,7 +91,7 @@ def pull_nchs_mortality_data(token: str, map_df: pd.DataFrame, test_mode: str): ) # Add population info - KEEP_COLUMNS.extend(["timestamp", "geo_id", "population"]) - df = df.merge(map_df, on="state")[KEEP_COLUMNS] - + keep_columns.extend(["timestamp", "geo_id", "population"]) + df = df.merge(map_df, on="state")[keep_columns] + return df diff --git a/nchs_mortality/delphi_nchs_mortality/run.py b/nchs_mortality/delphi_nchs_mortality/run.py index dbfc0777d..62ff3cefa 100644 --- a/nchs_mortality/delphi_nchs_mortality/run.py +++ b/nchs_mortality/delphi_nchs_mortality/run.py @@ -27,9 +27,9 @@ "prop" ] INCIDENCE_BASE = 100000 -geo_res = "state" +GEO_RES = "state" -def run_module(): +def run_module(): # pylint: disable=R0912,R0915 """Run module for processing NCHS mortality data.""" params = read_params() export_start_date = params["export_start_date"] @@ -65,7 +65,7 @@ def run_module(): sensor_name = "_".join(["wip", metric]) export_csv( df, - geo_name=geo_res, + geo_name=GEO_RES, export_dir=daily_export_dir, start_date=datetime.strptime(export_start_date, "%Y-%m-%d"), sensor=sensor_name, @@ -82,7 +82,7 @@ def run_module(): sensor_name = "_".join(["wip", metric, sensor]) export_csv( df, - geo_name=geo_res, + geo_name=GEO_RES, export_dir=daily_export_dir, start_date=datetime.strptime(export_start_date, "%Y-%m-%d"), sensor=sensor_name, @@ -104,7 +104,7 @@ def run_module(): params["aws_credentials"]) # Dont update cache from S3 (has daily files), only simulate a update_cache() call - weekly_arch_diff._cache_updated = True + weekly_arch_diff._cache_updated = True # pylint: disable=W0212 # Diff exports, and make incremental versions _, common_diffs, new_files = weekly_arch_diff.diff_exports() From 83d033728e685dc736fb1ec0184b3c143b2e784a Mon Sep 17 00:00:00 2001 From: chinandrew Date: Fri, 6 Nov 2020 13:02:55 -0800 Subject: [PATCH 2/3] Update nchs_mortality/delphi_nchs_mortality/run.py Co-authored-by: Katie Mazaitis --- nchs_mortality/delphi_nchs_mortality/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nchs_mortality/delphi_nchs_mortality/run.py b/nchs_mortality/delphi_nchs_mortality/run.py index 62ff3cefa..353e53e70 100644 --- a/nchs_mortality/delphi_nchs_mortality/run.py +++ b/nchs_mortality/delphi_nchs_mortality/run.py @@ -29,7 +29,7 @@ INCIDENCE_BASE = 100000 GEO_RES = "state" -def run_module(): # pylint: disable=R0912,R0915 +def run_module(): # pylint: disable=too-many-branches,too-many-statements """Run module for processing NCHS mortality data.""" params = read_params() export_start_date = params["export_start_date"] From 86a56b60fbc8d02215b38f8ca33003fc2678985b Mon Sep 17 00:00:00 2001 From: chinandrew Date: Fri, 6 Nov 2020 13:03:02 -0800 Subject: [PATCH 3/3] Update nchs_mortality/delphi_nchs_mortality/run.py Co-authored-by: Katie Mazaitis --- nchs_mortality/delphi_nchs_mortality/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nchs_mortality/delphi_nchs_mortality/run.py b/nchs_mortality/delphi_nchs_mortality/run.py index 353e53e70..e2c2339d8 100644 --- a/nchs_mortality/delphi_nchs_mortality/run.py +++ b/nchs_mortality/delphi_nchs_mortality/run.py @@ -104,7 +104,7 @@ def run_module(): # pylint: disable=too-many-branches,too-many-statements params["aws_credentials"]) # Dont update cache from S3 (has daily files), only simulate a update_cache() call - weekly_arch_diff._cache_updated = True # pylint: disable=W0212 + weekly_arch_diff._cache_updated = True # pylint: disable=protected-access # Diff exports, and make incremental versions _, common_diffs, new_files = weekly_arch_diff.diff_exports()