Open the context
Choose the project folder and name the files or behavior involved.
Compute sample variance for 2 through 10000 values bounded by 1e150 in magnitude using Welford updates. Check constant samples and large offsets, rejecting Booleans, non-finite values and invalid counts.
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.
from math import isfinite
def sample_variance(values):
if type(values) not in (list, tuple) or not 2 <= len(values) <= 10000:
raise ValueError("sample count")
if any(type(x) not in (int, float) or not -1e150 <= x <= 1e150
or not isfinite(x) for x in values):
raise ValueError("bounded finite samples")
mean, m2 = 0.0, 0.0
for n, x in enumerate(values, 1):
delta = x - mean
mean += delta / n
m2 += delta * (x - mean)
return m2 / (len(values) - 1)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.