feat: implemented unary positive operation for Obs and CObs classes,

included tolerance for exception in Obs.plot_piechart
This commit is contained in:
Fabian Joswig 2022-03-24 11:44:36 +00:00
parent da45a398b7
commit c9e1cd10af

View file

@ -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