Skip to content

Commit

Permalink
Remove warnings.catch_warnings context + ignore filter (#298)
Browse files Browse the repository at this point in the history
- *Category*: bugfix
- *JIRA issue*: [MIC-3599](https://jira.ihme.washington.edu/browse/MIC-3599)

Removes the context managers and ignore filters for FutureWarnings.

### Testing
Tested with the Maternal IV Iron simulation. When not coupled with changes to VPH to alleviate the FutureWarnings, FutureWarnings are emitted.
  • Loading branch information
mattkappel committed May 25, 2023
1 parent 85dc1b0 commit 9b98c5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
5 changes: 1 addition & 4 deletions src/vivarium/framework/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ def _groupby_new_state(
"""
output_map = {o: i for i, o in enumerate(outputs)}
# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
groups = pd.Series(index).groupby([output_map[d] for d in decisions])
groups = pd.Series(index).groupby([output_map[d] for d in decisions])
results = [(outputs[i], pd.Index(sub_group.values)) for i, sub_group in groups]
selected_outputs = [o for o, _ in results]
for output in outputs:
Expand Down
30 changes: 6 additions & 24 deletions src/vivarium/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,14 @@ def __init__(
if self.key_columns:
# Since there are key_columns we need to group the table by those
# columns to get the sub-tables to fit
# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
sub_tables = self.data.groupby(list(self.key_columns))
sub_tables = self.data.groupby(list(self.key_columns))
else:
# There are no key columns so we will fit the whole table
sub_tables = {None: self.data}.items()

self.interpolations = {}

# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
sub_tables = list(sub_tables)
sub_tables = list(sub_tables)
for key, base_table in sub_tables:
if (
base_table.empty
Expand Down Expand Up @@ -114,21 +108,15 @@ def __call__(self, interpolants: pd.DataFrame) -> pd.DataFrame:
validate_call_data(interpolants, self.key_columns, self.parameter_columns)

if self.key_columns:
# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
sub_tables = interpolants.groupby(list(self.key_columns))
sub_tables = interpolants.groupby(list(self.key_columns))
else:
sub_tables = [(None, interpolants)]
# specify some numeric type for columns so they won't be objects but will updated with whatever
# column type actually is
result = pd.DataFrame(
index=interpolants.index, columns=self.value_columns, dtype=np.float64
)
# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
sub_tables = list(sub_tables)
sub_tables = list(sub_tables)
for key, sub_table in sub_tables:
if sub_table.empty:
continue
Expand Down Expand Up @@ -226,19 +214,13 @@ def check_data_complete(data, parameter_columns):
for p in param_edges:
other_params = [p_ed[0] for p_ed in param_edges if p_ed != p]
if other_params:
# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
sub_tables = data.groupby(list(other_params))
sub_tables = data.groupby(list(other_params))
else:
sub_tables = {None: data}.items()

n_p_total = len(set(data[p[0]]))

# TODO: fix rather than suppress this FutureWarning
with warnings.catch_warnings():
warnings.simplefilter(action="ignore", category=FutureWarning)
sub_tables = list(sub_tables)
sub_tables = list(sub_tables)
for _, table in sub_tables:
param_data = table[[p[0], p[1]]].copy().sort_values(by=p[0])
start, end = param_data[p[0]].reset_index(drop=True), param_data[
Expand Down

0 comments on commit 9b98c5c

Please sign in to comment.