Skip to content

Commit

Permalink
Use explicit strictness in zips.
Browse files Browse the repository at this point in the history
  • Loading branch information
ast0815 authored Dec 19, 2022
1 parent 8859eaf commit 41a221b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions histoprint/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def format_bin(self, top, bottom, counts, width=1):
cycle(self.symbols),
cycle(self.fg_colors),
cycle(self.bg_colors),
strict=False,
):
if h:
if self.stack:
Expand Down Expand Up @@ -490,7 +491,7 @@ def format_histogram(self, counts):
)

# Write the bins
for c, t, b, w in zip(counts.T, top, bottom, self.bin_lines):
for c, t, b, w in zip(counts.T, top, bottom, self.bin_lines, strict=False):
hist_string += self.bin_formatter.format_bin(t, b, c, w)

if self.summary:
Expand All @@ -516,6 +517,7 @@ def summarize(self, counts, top, bottom, legend_only=False):
cycle(self.bin_formatter.symbols),
cycle(self.bin_formatter.fg_colors),
cycle(self.bin_formatter.bg_colors),
strict=False,
):
# Pad label to make room for numbers below
lab = f"{lab:<9}"
Expand All @@ -535,14 +537,14 @@ def summarize(self, counts, top, bottom, legend_only=False):

# Second line: Total
summary += " " * pad + "Tot:"
for c, w in zip(counts, label_widths):
for c, w in zip(counts, label_widths, strict=False):
tot = np.sum(c)
summary += f" {tot: .2e}" + " " * (w - 10)
summary += "\n"

# Third line: Average
summary += " " * pad + "Avg:"
for c, w in zip(counts, label_widths):
for c, w in zip(counts, label_widths, strict=False):
try:
average = np.average(bin_values, weights=c)
except ZeroDivisionError:
Expand All @@ -552,7 +554,7 @@ def summarize(self, counts, top, bottom, legend_only=False):

# Fourth line: std
summary += " " * pad + "Std:"
for c, w in zip(counts, label_widths):
for c, w in zip(counts, label_widths, strict=False):
try:
average = np.average(bin_values, weights=c)
std = np.sqrt(np.average((bin_values - average) ** 2, weights=c))
Expand Down

0 comments on commit 41a221b

Please sign in to comment.