diff --git a/cobaya/collection.py b/cobaya/collection.py index 400c0053..4d717a94 100644 --- a/cobaya/collection.py +++ b/cobaya/collection.py @@ -496,11 +496,11 @@ def _check_logps(self, temperature_only=False, extra_tolerance=False): temperature = compute_temperature( -self["minuslogpost"], -self["minuslogprior"], -self["chi2"] * 0.5, check=True, extra_tolerance=extra_tolerance) - except AssertionError: + except AssertionError as excpt: raise LoggedError( self.log, "The sample seems to have an inconsistent temperature. " "This could be due to input file truncation on the last line " - "due to crash/being killed before complete.") + "due to crash/being killed before complete.") from excpt if not temperature_only: tols = { "rtol": 1e-4 * (10 if extra_tolerance else 1), diff --git a/cobaya/tools.py b/cobaya/tools.py index 8c4887e0..d15839ab 100644 --- a/cobaya/tools.py +++ b/cobaya/tools.py @@ -506,17 +506,17 @@ def load_DataFrame(file_name, skip=0, root_file_name=None): inp, sep=" ", header=None, names=cols, comment="#", skipinitialspace=True, skiprows=skip, index_col=False) - if not data.empty: - # Check if the last row contains any NaNs - if data.iloc[-1].isna().any(): - log.warning("Last row of %s is incomplete or contains NaNs", file_name) - # If the second-to-last row exists and doesn't contain NaNs, - # delete the last row assuming this was due to crash on write - if len(data) > 1 and not data.iloc[-2].isna().any(): - data = data.iloc[:-1] - log.info(f"Saving {file_name} deleting last (in)complete line") - truncate_to_end_line(file_name) - return data + if not data.empty: + # Check if the last row contains any NaNs + if data.iloc[-1].isna().any(): + log.warning("Last row of %s is incomplete or contains NaNs", file_name) + # If the second-to-last row exists and doesn't contain NaNs, + # delete the last row assuming this was due to crash on write + if len(data) > 1 and not data.iloc[-2].isna().any(): + data = data.iloc[:-1] + log.info(f"Saving {file_name} deleting last (in)complete line") + truncate_to_end_line(file_name) + return data def prepare_comment(comment):