ML Foundations
Python statistics.quantiles changed its one-sample rule
Python 3.12 raises StatisticsError for a one-value input to statistics.quantiles; Python 3.13 changed that behavior. Check the supported runtime when handling tiny samples.

Evidence and testing
Review record: Tensor Almanac automated evidence gate (no independent human review). Example versions, recorded outputs and limitations appear below.
Python 3.12 rejects a one-value sample
In Python 3.12, `statistics.quantiles()` requires at least two data points. Passing a one-value list raises `StatisticsError`, even though the call uses the default quartile setting. This matters when a dataset is accumulated incrementally and a first observation is processed before the second arrives. [1]
The example catches that exception on the available Python 3.12 runtime, then calls `quantiles()` with two values and confirms that quartiles produce three cut points. `n=4` means four intervals, so the function returns `n - 1` boundaries. The result does not imply that two observations make a statistically stable estimate; it only demonstrates the API contract. [1]
Executed with Python 3.12.14; assertions passed.
"""Show Python 3.12's minimum sample size for statistics.quantiles."""
from statistics import StatisticsError, quantiles
try:
quantiles([7])
except StatisticsError as error:
print("one value rejected:", isinstance(error, StatisticsError))
cuts = quantiles([7, 9], n=4)
print("two values, quartile cuts:", cuts)
assert len(cuts) == 3
Recorded output
one value rejected: True two values, quartile cuts: [6.5, 8.0, 9.5]
References: [1]
The single-sample behavior changed in Python 3.13
Python 3.13 changed `statistics.quantiles()` so a single data point no longer raises an exception. The release documentation explains that this supports estimates that can be refined as additional samples arrive. Code that must also run on Python 3.12 should not assume this newer behavior is available. [2]
If a function promises one behavior across runtimes, check the input length yourself and choose an application-level result for the one-value case. For example, defer quantile calculation until two values exist, or handle the degenerate sample explicitly. Keep this policy separate from the version-specific library exception. [1, 2]
Treat the method and sample size as separate choices
The `method` option controls how cut points are interpolated; it does not remove the 3.12 minimum sample-size rule. The default `exclusive` method is intended for samples that may omit more extreme population values, while `inclusive` is intended when observed data include the extremes. [1]
This short example tests only the 3.12 exception and a two-value call. The Python 3.13 behavior is sourced from its official documentation, not executed in this runtime. For production compatibility, test the exact Python versions your application supports and define the one-sample result deliberately. [1, 2]