Skip to content

Commit

Permalink
differentiate the case of inconsistent versions
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Apr 5, 2022
1 parent 23292e9 commit 2977068
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions validphys2/src/validphys/fitdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def load_fitinfo(replica_path, prefix):
If the ``.json`` file does not exist an old-format fit is assumed and ``old_load_fitinfo``
will be called instead.
"""
p = replica_path / (prefix + '.json')
p = replica_path / (prefix + ".json")
if not p.exists():
return _old_load_fitinfo(p.with_suffix(".fitinfo"))
fitinfo_dict = json.loads(p.read_text(encoding="utf-8"))
Expand Down Expand Up @@ -445,36 +445,22 @@ def print_systype_overlap(groups_commondata, group_dataset_inputs_by_metadata):
def fit_code_version(fit):
""" Returns table with the code version from ``replica_1/{fitname}.json`` files.
"""
vinfo = previnfo = None
vinfo = {}
for json_path in fit.path.glob(f"nnfit/replica_*/{fit.name}.json"):
vinfo = json.loads(json_path.read_text(encoding="utf-8")).get("version")
if previnfo is not None and vinfo != previnfo:
# There's a mismatch of versions, just get out and say that it was unavailable
print(vinfo)
print(previnfo)
vinfo = None
break
previnfo = None

if vinfo is None:
# There was no version or json files in the fit, it must be old
vinfo_df = pd.DataFrame([("unavailable", "unavailable")]).set_index(0)
else:
vinfo_df = pd.DataFrame(vinfo.items()).set_index(0)
tmp = json.loads(json_path.read_text(encoding="utf-8")).get("version")
if (vinfo and vinfo != tmp) or tmp is None:
vinfo = {i: "inconsistent" for i in tmp}
break
vinfo = tmp

vinfo_df.columns = [fit.name]
vinfo_df.index.name = "module"
return vinfo_df
return pd.DataFrame(vinfo.items(), columns=["module", fit.name]).set_index("module")

fits_fit_code_version = collect("fit_code_version", ("fits",))

@table
def fits_version_table(fits_fit_code_version):
""" Produces a table of version information for multiple fits."""
vtable = pd.concat(fits_fit_code_version, axis=1)
# Drops any rows starting with "unavailable"
# If no such row is present, the error is suppressed and nothing changes
vtable.drop("unavailable", inplace=True, errors="ignore")
# Fill NaNs with "unavailable"
vtable.fillna("unavailable", inplace=True)
return vtable

0 comments on commit 2977068

Please sign in to comment.