Skip to content

Commit

Permalink
Add support for pandas 2
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Mar 21, 2024
1 parent 0556c35 commit 5c39d6f
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
REQUIREMENTS = [
"resdata>=4.0.0",
"numpy",
"pandas<2",
"pandas",
"pyyaml>=5.1",
]

Expand Down
2 changes: 1 addition & 1 deletion src/fmu/ensemble/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def load_smry(self, realization, smryvector, time_index="yearly", smryerror=None
realization
)
virtobs["observations"] = []
for date, value in dataseries.iteritems():
for date, value in dataseries.items():
virtobs["observations"].append(
{"value": value, "error": smryerror, "date": date}
)
Expand Down
7 changes: 0 additions & 7 deletions src/fmu/ensemble/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,7 @@ def load_status(self):
on_bad_lines="skip",
)

# dtype str messes up a little bit, pre-Pandas 0.24.1 gives 'None' as
# a string where data is missing.
status.replace("None", "", inplace=True)
# While Pandas 0.24.1 will insert proper Null values in those cells,
# we fill them with the empty string for the rest of this code to work
status.fillna("", inplace=True)
# It should be ok to have both of these statements running, but the
# replace() is probably superfluous when pandas 0.23 is gone.

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

Expand Down
6 changes: 3 additions & 3 deletions src/fmu/ensemble/virtualensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ def add_realization(self, realization, realidx=None, overwrite=False):
if key not in self.data.keys():
self.data[key] = dframe
else:
self.data[key] = self.data[key].append(
dframe, ignore_index=True, sort=True
self.data[key] = pd.concat(
[self.data[key], dframe], ignore_index=True, sort=True
)
self.update_realindices()

Expand Down Expand Up @@ -1030,7 +1030,7 @@ def get_smry_meta(self, column_keys=None):
return (
self.get_df("__smry_metadata")
.set_index("SMRYCOLUMN")
.loc[matches, :]
.loc[list(matches), :]
.replace({np.nan: None})
.to_dict(orient="index")
)
Expand Down
2 changes: 1 addition & 1 deletion src/fmu/ensemble/virtualrealization.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def get_smry_meta(self, column_keys=None):
return (
self.get_df("__smry_metadata")
.set_index("SMRYCOLUMN")
.loc[matches, :]
.loc[list(matches), :]
.to_dict(orient="index")
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ensemblecombination.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_ensemblecomb_observations():
obs.load_smry(mean, "FOPT", time_index="yearly")
mis = obs.mismatch(delta_ens)
# Realization 4 is best representing the mean delta FOPT:
assert mis.groupby("REAL").sum()["L2"].sort_values().index.values[0] == 4
assert mis.groupby("REAL")["L2"].sum().sort_values().index.values[0] == 4
# (this is the same as the representative realization for mean as
# found in test_observations.py::test_virtual_observations)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def test_virtual_observations():
mis = obs.mismatch(ens)

closest_realization = (
mis.groupby("REAL").sum()["L2"].sort_values().index.values[0]
mis.groupby("REAL")["L2"].sum().sort_values().index.values[0]
)
representative_realizations[virtrealname] = closest_realization

Expand Down Expand Up @@ -707,7 +707,7 @@ def test_virtual_observations():
mis = obs.mismatch(ens)

closest_realization = (
mis.groupby("REAL").sum()["L2"].sort_values().index.values[0]
mis.groupby("REAL")["L2"].sum().sort_values().index.values[0]
)
vrepresentative_realizations[virtrealname] = closest_realization

Expand Down
4 changes: 2 additions & 2 deletions tests/test_virtualensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def test_todisk(tmpdir):
# Columns that only contains NaN will not have their
# type preserved, this is too much to ask for, especially
# with CSV files. So we drop columns with NaN
virtframe = vens.get_df(frame).dropna("columns")
diskframe = fromdisk.get_df(frame).dropna("columns")
virtframe = vens.get_df(frame).dropna(axis="columns")
diskframe = fromdisk.get_df(frame).dropna(axis="columns")

# It would be nice to be able to use pd.Dataframe.equals,
# but it is too strict, as columns with mixed type number/strings
Expand Down

0 comments on commit 5c39d6f

Please sign in to comment.