Skip to content

Commit

Permalink
Silence pandas FutureWarning while waiting for dropping Python 3.6 (
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored May 4, 2022
1 parent 1de1fa4 commit 11f2e9b
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ class variable keyvaluedata directly, or rerun this function.
"FULLPATH": fullpath,
"BASENAME": os.path.split(localpath)[-1],
}
self.files = self.files.append(filerow, ignore_index=True)
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
# append deprecated on pandas >= 1.4,
# switch to e.g. pandas.concat when dropping Python 3.6 support
self.files = self.files.append(filerow, ignore_index=True)
try:
keyvalues = pd.read_csv(
fullpath,
Expand Down Expand Up @@ -490,18 +494,24 @@ def load_status(self):
# to be present.
return pd.DataFrame() # will be empty
errorcolumns = ["error" + str(x) for x in range(0, 10)]
status = pd.read_csv(
statusfile,
sep=r"\s+",
skiprows=1,
header=None,
names=["FORWARD_MODEL", "colon", "STARTTIME", "dots", "ENDTIME"]
+ errorcolumns,
dtype=str,
engine="python",
error_bad_lines=False,
warn_bad_lines=True,
)

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
# error_bad_lines and warn_bad_lines emit a FutureWarning on pandas >= 1.3,
# these two arguments can be replaced with on_bad_lines="skip"
# when dropping Python 3.6 support.
status = pd.read_csv(
statusfile,
sep=r"\s+",
skiprows=1,
header=None,
names=["FORWARD_MODEL", "colon", "STARTTIME", "dots", "ENDTIME"]
+ errorcolumns,
dtype=str,
engine="python",
error_bad_lines=False,
warn_bad_lines=True,
)

# dtype str messes up a little bit, pre-Pandas 0.24.1 gives 'None' as
# a string where data is missing.
Expand Down

0 comments on commit 11f2e9b

Please sign in to comment.