Open the context
Choose the project folder and name the files or behavior involved.
Return the median and unscaled median absolute deviation of 1–4096 finite numbers bounded by ±10^100. Test even lengths, equal values and an outlier, rejecting Booleans or nonfinite values while leaving the input order intact.
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 math
def median_deviation(values):
if type(values) is not list or not 1 <= len(values) <= 4096:
raise ValueError("mad.input")
if any(type(x) not in (int, float) or not -10**100 <= x <= 10**100 or not math.isfinite(x) for x in values):
raise ValueError("mad.value")
def median(items):
ordered = sorted(items)
n = len(ordered)
return float(ordered[n//2]) if n % 2 else ordered[n//2-1]/2+ordered[n//2]/2
center = median(values)
return center, median([abs(x-center) for x in values])
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.