Let's be explicit with asserts; there was a bug in histogram
[python_utils.git] / histogram.py
index 993b5036d737cdcd705ef411e5cbcf70ba0da911..cea8b766e3f88a3e197cbdff128539f199fdc83a 100644 (file)
@@ -81,12 +81,12 @@ class SimpleHistogram(Generic[T]):
                 last_bucket_start = bucket[0]  # beginning of range
             if max_population is None or pop > max_population:
                 max_population = pop  # bucket with max items
-        if max_population is None:
+        if len(self.buckets) == 0 or max_population is None:
             return txt
 
         max_label_width: Optional[int] = None
-        lowest_start: int = None
-        highest_end: int = None
+        lowest_start: Optional[int] = None
+        highest_end: Optional[int] = None
         for bucket in sorted(self.buckets, key=lambda x: x[0]):
             start = bucket[0]
             if lowest_start is None:
@@ -100,9 +100,9 @@ class SimpleHistogram(Generic[T]):
                 max_label_width = label_width
             if start == last_bucket_start:
                 break
-        assert max_label_width
-        assert lowest_start
-        assert highest_end
+        assert max_label_width is not None
+        assert lowest_start is not None
+        assert highest_end is not None
 
         sigma_label = f'[{label_formatter}..{label_formatter}): ' % (
             lowest_start,