Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix sample OverflowError

  • Loading branch information...
commit 31f959a4e2df938e8c41c0789da3ac5c84da9b1f 1 parent 849ade3
@cyberdelia authored
Showing with 15 additions and 2 deletions.
  1. +6 −1 metrology/stats/sample.py
  2. +9 −1 tests/instruments/test_histogram.py
View
7 metrology/stats/sample.py
@@ -1,5 +1,7 @@
import math
import random
+import sys
+
from time import time
from atomic import Atomic
@@ -89,7 +91,10 @@ def update(self, value, timestamp=None):
if not timestamp:
timestamp = time()
with self.lock:
- priority = self.weight(timestamp - self.start_time) / random.random()
+ try:
+ priority = self.weight(timestamp - self.start_time) / random.random()
+ except OverflowError:
+ priority = sys.float_info.max
new_count = self.counter.update(lambda v: v + 1)
if math.isnan(priority):
View
10 tests/instruments/test_histogram.py
@@ -1,7 +1,8 @@
from threading import Thread
from unittest import TestCase
-from metrology.instruments.histogram import HistogramUniform, HistogramExponentiallyDecaying
+from metrology.stats.sample import ExponentiallyDecayingSample
+from metrology.instruments.histogram import Histogram, HistogramUniform, HistogramExponentiallyDecaying
class HistogramTest(TestCase):
@@ -114,3 +115,10 @@ def update():
thread.join()
snapshot = histogram.snapshot
self.assertEqual(49.5, snapshot.median)
+
+ def test_sample_overflow_error(self):
+ sample = ExponentiallyDecayingSample(Histogram.DEFAULT_SAMPLE_SIZE, Histogram.DEFAULT_ALPHA)
+ sample.start_time = 946681200.0
+ histogram = Histogram(sample)
+ histogram.update(5)
+ self.assertEqual(5, histogram.min)
Please sign in to comment.
Something went wrong with that request. Please try again.