Bug report
Bug description:
Documented behaviour: The linear_regression docstring states: "Return the slope and intercept of simple linear regression parameters estimated using ordinary least squares."
Expected: Slope 1.0 and intercept 0.0.
Actual: Raises StatisticsError: x is constant.
import math
import statistics
from fractions import Fraction
x = y = [0.0, 1e-200]
data = {"x": x, "y": y, "proportional": False}
if not (len(x) == len(y) == 2 and x[0] != x[1]
and all(math.isfinite(v) for v in x + y)):
print("REFUTATION REJECTED:", "invalid regression input")
else:
X, Y = list(map(Fraction, x)), list(map(Fraction, y))
# Two distinct points determine the unique zero-residual OLS line.
slope = (Y[1] - Y[0]) / (X[1] - X[0])
expected = (float(slope), float(Y[0] - slope * X[0]))
try:
actual = tuple(statistics.linear_regression(x, y))
except Exception as e:
actual = {"exception": type(e).__name__, "message": str(e)}
if actual != expected:
print("REFUTATION CONFIRMED:", data, "actual:", actual, "expected:", expected)
else:
print("REFUTATION REJECTED:", "actual matches independent OLS expectation")
Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library statistics:
REFUTATION CONFIRMED: {'x': [0.0, 1e-200], 'y': [0.0, 1e-200], 'proportional': False} actual: {'exception': 'StatisticsError', 'message': 'x is constant'} expected: (1.0, 0.0)
This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/statistics-20261003-045701-c2
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Bug report
Bug description:
Documented behaviour: The linear_regression docstring states: "Return the slope and intercept of simple linear regression parameters estimated using ordinary least squares."
Expected: Slope 1.0 and intercept 0.0.
Actual: Raises StatisticsError: x is constant.
Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library
statistics:This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/statistics-20261003-045701-c2
CPython versions tested on:
3.14
Operating systems tested on:
Windows