From 313dec7ceed01a00cc300e27cff97872b5d9853e Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 20 Dec 2022 17:18:25 +0100 Subject: [PATCH] refactor: _assert_equal_properties simplified. --- pyerrors/misc.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pyerrors/misc.py b/pyerrors/misc.py index bbfb8e7d..cf0dd18a 100644 --- a/pyerrors/misc.py +++ b/pyerrors/misc.py @@ -105,16 +105,11 @@ def gen_correlated_data(means, cov, name, tau=0.5, samples=1000): def _assert_equal_properties(ol, otype=Obs): - if not isinstance(ol[0], otype): - raise Exception("Wrong data type in list.") + otype = type(ol[0]) for o in ol[1:]: if not isinstance(o, otype): raise Exception("Wrong data type in list.") - if not ol[0].is_merged == o.is_merged: - raise Exception("All Obs in list have to have the same state 'is_merged'.") - if not ol[0].reweighted == o.reweighted: - raise Exception("All Obs in list have to have the same property 'reweighted'.") - if not ol[0].e_content == o.e_content: - raise Exception("All Obs in list have to be defined on the same set of configs.") - if not ol[0].idl == o.idl: - raise Exception("All Obs in list have to be defined on the same set of configurations.") + for attr in ["is_merged", "reweighted", "e_content", "idl"]: + if hasattr(ol[0], attr): + if not getattr(ol[0], attr) == getattr(o, attr): + raise Exception(f"All Obs in list have to have the same state '{attr}'.")