Skip to content

Commit

Permalink
Fix pandas deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Sep 10, 2024
1 parent acb4aa2 commit 7e678e3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,14 @@ def load_status(self):
status.fillna("", inplace=True)

errorjobs = status[errorcolumns[0]] != ""

# Merge any error strings:
error_string = (
status.loc[errorjobs, errorcolumns]
.astype(str)
.apply(" ".join, axis=1)
.apply(str.strip)
)
status["errorstring"] = np.nan
status["errorstring"] = pd.NA
status.loc[errorjobs, "errorstring"] = error_string
status.drop(errorcolumns, axis=1, inplace=True)

Expand Down
9 changes: 2 additions & 7 deletions src/fmu/ensemble/virtualrealization.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,10 @@ def get_smry(self, column_keys=None, time_index="monthly"):
]
if cum_columns:
smry[cum_columns] = (
smry[cum_columns]
.interpolate(method="time")
.fillna(method="ffill")
.fillna(method="bfill")
smry[cum_columns].interpolate(method="time").ffill().bfill()
)
if noncum_columns:
smry[noncum_columns] = (
smry[noncum_columns].fillna(method="bfill").fillna(value=0)
)
smry[noncum_columns] = smry[noncum_columns].bfill().fillna(value=0)

smry.index = smry.index.set_names(["DATE"])
return smry.loc[pd.to_datetime(time_index_dt)]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ def test_ensemble_ecl():
# For oil industry, p15 on FOPT should yield a larger value than p85.
# But the quantiles we get out follows the rest of the world
# so we check for the opposite.
assert df_stats["FOPT"]["p85"][-1] > df_stats["FOPT"]["p15"][-1]

assert df_stats["FOPT"]["p85"].iloc[-1] > df_stats["FOPT"]["p15"].iloc[-1]

with pytest.raises(ValueError):
reekensemble.get_smry_stats(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ def test_volumetric_rates():
# Calculate cumulative production from the computed volumetric daily rates:
dayscum["FOPRcum"] = dayscum["FOPR"] * dayscum["DIFFDAYS"]
# Check that this sum is equal to FOPT between first and last date:
assert dayscum["FOPRcum"].sum() == pytest.approx(dcum["FOPT"][-1] - dcum["FOPT"][0])
assert dayscum["FOPRcum"].sum() == pytest.approx(
dcum["FOPT"].iloc[-1] - dcum["FOPT"].iloc[0]
)
# (here we could catch an error in case we don't support leap days)

# Monthly rates between the random dates:
Expand Down

0 comments on commit 7e678e3

Please sign in to comment.