Skip to content

Commit f4cebde

Browse files
committed
Backport fix from PR #510. [ci skip]
1 parent 48b838d commit f4cebde

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/BioSimSpace/FreeEnergy/_relative.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,16 @@ def _somd2_extract(parquet_file, T=None, estimator="MBAR"):
10591059
raise ValueError("Parquet metadata does not contain 'lambda'.")
10601060
if not is_mbar:
10611061
try:
1062-
lambda_grad = metadata["lambda_grad"]
1062+
# Normalise to floats to match the DataFrame column type expected
1063+
# by alchemlyb (handles both old float and new string metadata).
1064+
lambda_grad = [float(v) for v in metadata["lambda_grad"]]
10631065
except:
10641066
raise ValueError("Parquet metadata does not contain 'lambda grad'")
10651067
else:
10661068
try:
1067-
lambda_grad = metadata["lambda_grad"]
1069+
# Normalise to floats to match the DataFrame column type expected
1070+
# by alchemlyb (handles both old float and new string metadata).
1071+
lambda_grad = [float(v) for v in metadata["lambda_grad"]]
10681072
except:
10691073
lambda_grad = []
10701074

@@ -1078,6 +1082,19 @@ def _somd2_extract(parquet_file, T=None, estimator="MBAR"):
10781082
# Convert to a pandas dataframe.
10791083
df = table.to_pandas()
10801084

1085+
# Normalise column names to floats so that comparisons are consistent
1086+
# regardless of whether the parquet was written with float keys (old
1087+
# sire) or formatted string keys (new sire). float("0.10000") and
1088+
# float("0.1") give the same IEEE754 value, so old and new files are
1089+
# handled identically and the alchemlyb index check passes.
1090+
df.columns = [
1091+
float(c)
1092+
if isinstance(c, str)
1093+
and c.replace(".", "", 1).replace("-", "", 1).isdigit()
1094+
else c
1095+
for c in df.columns
1096+
]
1097+
10811098
if is_mbar:
10821099
# Extract all columns other than those used for the gradient.
10831100
df = df[[x for x in df.columns if x not in lambda_grad]]

0 commit comments

Comments
 (0)