Skip to content

Fix failing hhs test and address pandas update in delphi_utils #1822

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion _delphi_utils_python/delphi_utils/flash_eval/eval_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions _delphi_utils_python/delphi_utils/geomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion _delphi_utils_python/delphi_utils/validator/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions _delphi_utils_python/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion _delphi_utils_python/tests/test_geomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions _delphi_utils_python/tests/validator/test_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hhs_hosp/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down