Open the context
Choose the project folder and name the files or behavior involved.
Bin up to 4096 finite values using two to 257 strictly increasing edges bounded by ±10^100. Test edge equality, empty observations and outliers, include the final right edge and report underflow and overflow without changing either list.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import bisect, math
def histogram(edges, values):
if type(edges) is not list or type(values) is not list or not 2 <= len(edges) <= 257 or len(values) > 4096:
raise ValueError("bins.shape")
if any(type(x) not in (int, float) or not -10**100 <= x <= 10**100 or not math.isfinite(x) for x in edges+values):
raise ValueError("bins.value")
if any(a >= b for a, b in zip(edges, edges[1:])):
raise ValueError("bins.edges")
counts, under, over = [0]*(len(edges)-1), 0, 0
for value in values:
if value < edges[0]:
under += 1
elif value > edges[-1]:
over += 1
else:
counts[min(bisect.bisect_right(edges, value)-1, len(counts)-1)] += 1
return counts, under, over
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.