From ea6e3d756223a16d0061478c82af56ce544b0abe Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 4 Apr 2023 12:42:21 -0400 Subject: [PATCH 1/5] don't use loc to avoid a future warning about calling int on a single element series --- hhs_hosp/tests/test_run.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hhs_hosp/tests/test_run.py b/hhs_hosp/tests/test_run.py index 4719ce8db..a88b240be 100644 --- a/hhs_hosp/tests/test_run.py +++ b/hhs_hosp/tests/test_run.py @@ -100,8 +100,8 @@ def test_transform_signal_pop(): 'timestamp': [datetime(year=2020, month=1, day=1)]*2, 'val': [15., 150.],}) - pa_pop = int(state_pop.loc[state_pop.state_id == "pa", "pop"]) - wv_pop = int(state_pop.loc[state_pop.state_id == "wv", "pop"]) + pa_pop = int(state_pop[state_pop.state_id == "pa"]["pop"].iloc[0]) + wv_pop = int(state_pop[state_pop.state_id == "wv"]["pop"].iloc[0]) pd.testing.assert_frame_equal( transform_signal( CONFIRMED_PROP, From e37c73614924eb4e6db12551198b6ba1ec7044ea Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 4 Apr 2023 15:49:11 -0400 Subject: [PATCH 2/5] set numeric_only in geomap sum to avoid concatting strings --- _delphi_utils_python/delphi_utils/geomap.py | 6 +++--- _delphi_utils_python/tests/test_geomap.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_delphi_utils_python/delphi_utils/geomap.py b/_delphi_utils_python/delphi_utils/geomap.py index d5446d1ea..4782798a0 100644 --- a/_delphi_utils_python/delphi_utils/geomap.py +++ b/_delphi_utils_python/delphi_utils/geomap.py @@ -401,9 +401,9 @@ def replace_geocode( df.drop("weight", axis=1, inplace=True) if not date_col is None: - df = df.groupby([date_col, new_col]).sum().reset_index() + df = df.groupby([date_col, new_col]).sum(numeric_only=True).reset_index() else: - df = df.groupby([new_col]).sum().reset_index() + df = df.groupby([new_col]).sum(numeric_only=True).reset_index() return df def add_population_column(self, data, geocode_type, geocode_col=None, dropna=True): @@ -501,7 +501,7 @@ def fips_to_megacounty( ) data.set_index([fips_col, date_col], inplace=True) data = data.join(mega_data) - data = data.reset_index().groupby([date_col, mega_col]).sum() + data = data.reset_index().groupby([date_col, mega_col]).sum(numeric_only=True) return data.reset_index() def as_mapper_name(self, geo_type, state="state_id"): diff --git a/_delphi_utils_python/tests/test_geomap.py b/_delphi_utils_python/tests/test_geomap.py index fb582e7d5..0925a1712 100644 --- a/_delphi_utils_python/tests/test_geomap.py +++ b/_delphi_utils_python/tests/test_geomap.py @@ -196,7 +196,7 @@ def test_load_fips_chngfips_table(self, geomapper): def test_load_jhu_uid_fips_table(self, geomapper): jhu_data = geomapper.get_crosswalk(from_code="jhu_uid", to_code="fips") - assert np.allclose(jhu_data.groupby("jhu_uid").sum(), 1.0) + assert np.allclose(jhu_data.groupby("jhu_uid").sum(numeric_only=True), 1.0) def test_load_zip_hrr_table(self, geomapper): zip_data = geomapper.get_crosswalk(from_code="zip", to_code="hrr") From fab4c622584d2e1de3241f14789ab6ad1a5afa1f Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 4 Apr 2023 16:34:18 -0400 Subject: [PATCH 3/5] replace iteritems --- _delphi_utils_python/delphi_utils/flash_eval/eval_day.py | 2 +- _delphi_utils_python/delphi_utils/validator/dynamic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_delphi_utils_python/delphi_utils/flash_eval/eval_day.py b/_delphi_utils_python/delphi_utils/flash_eval/eval_day.py index 373b486d6..660fca042 100644 --- a/_delphi_utils_python/delphi_utils/flash_eval/eval_day.py +++ b/_delphi_utils_python/delphi_utils/flash_eval/eval_day.py @@ -147,7 +147,7 @@ def output(evd_ranking, day, lag, signal, logger): """ starter_link = f"{HTML_LINK}{(day+pd.Timedelta(f'{lag}d')).strftime('%Y-%m_%d')}" p_text = "" - for j, (index, value) in enumerate(evd_ranking.sort_values(ascending=False).iteritems()): + for j, (index, value) in enumerate(evd_ranking.sort_values(ascending=False).items()): if j < 30: start_link = f"{starter_link},{day.strftime('%Y-%m_%d')},{index}" p_text += f"\t{start_link}|*{index}*, {'{:.2f}'.format(value)}>\n" diff --git a/_delphi_utils_python/delphi_utils/validator/dynamic.py b/_delphi_utils_python/delphi_utils/validator/dynamic.py index 7e3524779..6beb5712b 100644 --- a/_delphi_utils_python/delphi_utils/validator/dynamic.py +++ b/_delphi_utils_python/delphi_utils/validator/dynamic.py @@ -195,7 +195,7 @@ def replace_first_six(df, start_date): start_date = self.params.time_window.start_date) if not error_df.empty: - for index, value in error_df.iteritems(): + for index, value in error_df.items(): report.add_raised_error( ValidationFailure("check_val_missing", geo_type=geo_type, From 53f0d0c161a5be235fb89db23f8f366faf9fd400 Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 4 Apr 2023 16:34:44 -0400 Subject: [PATCH 4/5] replace append --- _delphi_utils_python/tests/test_export.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/_delphi_utils_python/tests/test_export.py b/_delphi_utils_python/tests/test_export.py index 6076f362d..04cd2f6ce 100644 --- a/_delphi_utils_python/tests/test_export.py +++ b/_delphi_utils_python/tests/test_export.py @@ -250,15 +250,15 @@ def test_export_with_null_removal(self): """Test that `remove_null_samples = True` removes entries with null samples.""" _clean_directory(self.TEST_DIR) - df_with_nulls = self.DF.copy().append( - { + df_with_nulls = pd.concat( + [self.DF.copy(), + pd.DataFrame({ "geo_id": "66666", "timestamp": datetime(2020, 6, 6), "val": 10, "se": 0.2, "sample_size": pd.NA, - }, - ignore_index=True, + }, index = [0])] ) create_export_csv( @@ -283,15 +283,15 @@ def test_export_without_null_removal(self): """Test that `remove_null_samples = False` does not remove entries with null samples.""" _clean_directory(self.TEST_DIR) - df_with_nulls = self.DF.copy().append( - { + df_with_nulls = pd.concat( + [self.DF.copy(), + pd.DataFrame({ "geo_id": "66666", "timestamp": datetime(2020, 6, 6), "val": 10, "se": 0.2, "sample_size": pd.NA, - }, - ignore_index=True, + }, index = [0])] ) create_export_csv( From f6d564d86f6f53ba039856aeb4e45fca016a6bdb Mon Sep 17 00:00:00 2001 From: Nat DeFries <42820733+nmdefries@users.noreply.github.com> Date: Tue, 4 Apr 2023 16:34:57 -0400 Subject: [PATCH 5/5] make dates comparable --- _delphi_utils_python/tests/validator/test_dynamic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_delphi_utils_python/tests/validator/test_dynamic.py b/_delphi_utils_python/tests/validator/test_dynamic.py index 248e1b2aa..45d5a15d0 100644 --- a/_delphi_utils_python/tests/validator/test_dynamic.py +++ b/_delphi_utils_python/tests/validator/test_dynamic.py @@ -48,7 +48,7 @@ def test_half_padding(self): ref_df, test_df, ref_date, ref_date) # Check it only takes missing dates - so the last 5 dates - assert new_ref_df.time_value.max() == datetime.strptime("2021-01-11", + assert new_ref_df.time_value.max().date() == datetime.strptime("2021-01-11", "%Y-%m-%d").date() assert new_ref_df.shape[0] == 11 assert new_ref_df["val"].iloc[5] == 2 @@ -71,7 +71,7 @@ def test_full_padding(self): ref_df, test_df, ref_date, ref_date) # Check it only takes missing dates up to the day before the reference - assert new_ref_df.time_value.max() == datetime.strptime("2021-01-15", + assert new_ref_df.time_value.max().date() == datetime.strptime("2021-01-15", "%Y-%m-%d").date() assert new_ref_df.shape[0] == 15 assert new_ref_df["val"].iloc[5] == 2