Skip to content

Commit

Permalink
Fix pandas FutureWarnings (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv authored Sep 29, 2022
1 parent f162f0f commit c2e073f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
8 changes: 4 additions & 4 deletions webviz_subsurface/_components/tornado/_tornado_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ def _calculate_sensitivity_averages(
) -> List[Dict[str, Union[str, list, float]]]:
avg_per_sensitivity = []

for sens_name, sens_name_df in dframe.groupby(["SENSNAME"]):
for sens_name, sens_name_df in dframe.groupby("SENSNAME"):
# Excluding cases if `ref` is used as `SENSNAME`, and only one realization
# is present for this `SENSNAME`
if sens_name == "ref" and len(sens_name_df["REAL"].unique()) == 1:
continue

# If `SENSTYPE` is scalar get the mean for each `SENSCASE`
if (sens_name_df["SENSTYPE"] == "scalar").all():
for sens_case, sens_case_df in sens_name_df.groupby(["SENSCASE"]):
for sens_case, sens_case_df in sens_name_df.groupby("SENSCASE"):
avg_per_sensitivity.append(
{
"sensname": sens_name,
Expand Down Expand Up @@ -179,7 +179,7 @@ def _calculate_tornado_low_high_list(
) -> List[Dict[str, Union[str, list, float]]]:
low_high_per_sensitivity = []
for sensname, sens_name_df in pd.DataFrame(avg_per_sensitivity).groupby(
["sensname"]
"sensname"
):
low = sens_name_df.copy().loc[sens_name_df["values_ref"].idxmin()]
high = sens_name_df.copy().loc[sens_name_df["values_ref"].idxmax()]
Expand Down Expand Up @@ -259,7 +259,7 @@ def low_high_realizations_list(self) -> Dict[str, Dict]:
"real_low": sens_name_df["low_reals"].tolist()[0],
"real_high": sens_name_df["high_reals"].tolist()[0],
}
for sensname, sens_name_df in self.tornadotable.groupby(["sensname"])
for sensname, sens_name_df in self.tornadotable.groupby("sensname")
}

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion webviz_subsurface/_models/inplace_volumes_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def get_df(
aggregations.update({x: "mean" for x in parameters})

dframe = dframe.groupby(sum_over_groups).agg(aggregations).reset_index()
dframe = dframe.groupby(groups).mean().reset_index()
dframe = dframe.groupby(groups).mean(numeric_only=True).reset_index()

dframe = self.compute_property_columns(dframe, properties)
if "FLUID_ZONE" not in groups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ def delta_statistics(
lambda x: " | ".join([f"{x[sel]}" for sel in self.selectors]), axis=1
)

# Drop non-numerical columns before aggregations
df = df.drop(columns=["SOURCE", "PROPERTY"] + self.selectors)

df = df[df["ENSEMBLE"].isin([ensemble, delta_ensemble])]
df = df.pivot_table(columns=["ENSEMBLE"], index="label").reset_index()

Expand Down Expand Up @@ -311,6 +314,8 @@ def make_statistics_table(
if selector_values is not None:
df = self.filter_dataframe(df, self.selectors, selector_values)

# Drop non-numerical columns before aggregations
df = df.drop(columns=["SOURCE", "PROPERTY"] + self.selectors)
df = df[df["ENSEMBLE"].isin(ensembles)]
df = df.pivot_table(columns=["ENSEMBLE"], index="label").reset_index()
return self.make_table(df)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,13 @@ def make_tables(
statcols = ["Mean", "Stddev", "P90", "P10", "Min", "Max"]
groups = [x for x in groups if x != "REAL"]
responses = [x for x in responses if x != "REAL" and x is not None]
df_groups = dframe.groupby(groups) if groups else [(None, dframe)]

if not groups:
df_groups = [("", dframe)]
elif len(groups) == 1:
df_groups = dframe.groupby(groups[0])
else:
df_groups = dframe.groupby(groups)
data_properties = []
data_volcols = []
for response in responses:
Expand All @@ -383,10 +388,11 @@ def make_tables(
data.update(
FLUID_ZONE=(" + ").join(selections["filters"]["FLUID_ZONE"])
)

for idx, group in enumerate(groups):
data[group] = (
name if not isinstance(name, tuple) else list(name)[idx]
name
if name is not None or name is not isinstance(name, str)
else list(name)[idx]
)
if response in volumemodel.volume_columns:
data["Response"] = response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def histogram_options(uuid: str, tab: str) -> html.Div:
label="Histogram bins:",
id={"id": uuid, "tab": tab, "selector": "hist_bins"},
value=15,
step=1,
marks={1: 1, 10: 10, 20: 20, 30: 30},
min=1,
max=30,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def create_set_dframe(self, volume_dfs: List[pd.DataFrame]) -> pd.DataFrame:
"""Sum Eclipse and RMS volumetrics over the common disjoints sets."""
region_selectors = self.find_region_selectors()
set_data_list = []
for set_idx, df in self.disjoint_set_df.groupby(["SET"]):
for set_idx, df in self.disjoint_set_df.groupby("SET"):
for voldf in volume_dfs:
source = voldf["SOURCE"].unique()[0]
if "FIPNUM" in voldf.columns:
Expand All @@ -187,7 +187,7 @@ def create_set_dframe(self, volume_dfs: List[pd.DataFrame]) -> pd.DataFrame:
)
set_df = (
filtered_df.groupby(["ENSEMBLE", "REAL"])
.sum()
.sum(numeric_only=True)
.reset_index()
.drop(labels=["FIPNUM", "REGION", "ZONE"], errors="ignore")
)
Expand Down

0 comments on commit c2e073f

Please sign in to comment.