[Git][NTPsec/ntpsec][master] ntpclients/ntpviz.py: Better comment skewness and kurtosis in code.
Matt Selsky
Matthew.Selsky at twosigma.com
Fri Dec 13 05:46:32 UTC 2024
On Fri, Dec 13, 2024 at 04:37:33AM +0000, Gary E. Miller (@garyedmundsmiller) via vc wrote:
> ... ... @@ -186,8 +203,11 @@ class RunningStats(object):
> 186 203 self.variance = sum(pow((v-self.mu), 2) for v in values) / self.num
> 187 204 self.sigma = math.sqrt(self.variance)
> 188 205
> 189 - if math.isnan(self.sigma) or 1e-12 >= abs(self.sigma):
> 190 - # punt
> 206 + # Note: math.isnan(float("+Inf")) is false, so avoid isnan()
> 207 + # Use isfinite() instead.
> 208 + if ((not math.isfinite(self.sigma) or
> 209 + 1e-12 >= abs(self.sigma))):
> 210 + # Not finite, or too small. Punt
> 191 211 self.skewness = float('nan')
> 192 212 self.kurtosis = float('nan')
> 193 213 return
Hi Gary,
math.isfinite() was added in Python 3.2 per https://docs.python.org/3/library/math.html. Should we use math.isinf() instead in order to retain Python 2 compatibility until we decide to drop that?
Thanks,
-Matt
More information about the devel
mailing list