From 1ab16612d91be4f1e35bea790329e7eded12ff7b Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Dec 2021 16:24:40 +0000 Subject: [PATCH 1/2] feat: changed the way empty obs are initialized --- pyerrors/obs.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 099f3157..5690afd8 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -68,8 +68,9 @@ class Obs: already subtracted from the samples """ - if means is None and samples is not None: - if len(samples) != len(names): + sample_length = len(samples) + if means is None and sample_length: + if sample_length != len(names): raise Exception('Length of samples and names incompatible.') if idl is not None: if len(idl) != len(names): @@ -86,11 +87,7 @@ class Obs: if min(len(x) for x in samples) <= 4: raise Exception('Samples have to have at least 5 entries.') - if names: - self.names = sorted(names) - else: - self.names = [] - + self.names = sorted(names) self.shape = {} self.r_values = {} self.deltas = {} @@ -100,7 +97,7 @@ class Obs: self.covobs = covobs self.idl = {} - if samples is not None: + if sample_length: if idl is not None: for name, idx in sorted(zip(names, idl)): if isinstance(idx, range): @@ -1632,7 +1629,7 @@ def cov_Obs(means, cov, name, grad=None): co : Covobs Covobs to be embedded into the Obs """ - o = Obs(None, None) + o = Obs([], []) o._value = co.value o.names.append(co.name) o.covobs[co.name] = co From 5f2e33ccda1019891d0300f7a51909e935c59c0a Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Dec 2021 16:31:42 +0000 Subject: [PATCH 2/2] feat: repetative len(sample) calles reintroduced --- pyerrors/obs.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 5690afd8..411fe278 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -68,9 +68,8 @@ class Obs: already subtracted from the samples """ - sample_length = len(samples) - if means is None and sample_length: - if sample_length != len(names): + if means is None and len(samples): + if len(samples) != len(names): raise Exception('Length of samples and names incompatible.') if idl is not None: if len(idl) != len(names): @@ -97,7 +96,7 @@ class Obs: self.covobs = covobs self.idl = {} - if sample_length: + if len(samples): if idl is not None: for name, idx in sorted(zip(names, idl)): if isinstance(idx, range):