From c9e1cd10af15ec6e79398ceaf90f05ad0c20aa3e Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Thu, 24 Mar 2022 11:44:36 +0000 Subject: [PATCH] feat: implemented unary positive operation for Obs and CObs classes, included tolerance for exception in Obs.plot_piechart --- pyerrors/obs.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index bf8575bd..6874bd12 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -582,7 +582,7 @@ class Obs: ensemble to the error and returns a dictionary containing the fractions.""" if not hasattr(self, 'e_dvalue'): raise Exception('Run the gamma method first.') - if self._dvalue == 0.0: + if np.isclose(0.0, self._dvalue, atol=1e-15): raise Exception('Error is 0.0') labels = self.e_names sizes = [self.e_dvalue[name] ** 2 for name in labels] / self._dvalue ** 2 @@ -729,6 +729,9 @@ class Obs: def __rsub__(self, y): return -1 * (self - y) + def __pos__(self): + return self + def __neg__(self): return -1 * self @@ -911,8 +914,11 @@ class CObs: def __abs__(self): return np.sqrt(self.real**2 + self.imag**2) - def __neg__(other): - return -1 * other + def __pos__(self): + return self + + def __neg__(self): + return -1 * self def __eq__(self, other): return self.real == other.real and self.imag == other.imag