statistics: quantiles(method="inclusive") Still Avoids Min/Max (tested)

statistics.quantiles() defaults to method='exclusive', which can return cut points outside the data's actual range when n is large relative to the sample size. Switching to method='inclusive' is the documented alternative -- we measured whether it actually fixes the out-of-range problem, and what it does instead.

1. method="inclusive" eliminates every out-of-range value that method="exclusive" produced

import statistics as st

data = list(range(1, 11))  # 1..10

excl = st.quantiles(data, n=100, method="exclusive")
incl = st.quantiles(data, n=100, method="inclusive")

print(min(excl), max(excl))
print(min(incl), max(incl))
0.11 10.89
1.09 9.91

Measured: the default exclusive method's 99 cut points range from 0.11 to 10.89 -- outside the data's actual 1-10 range entirely. Switching to method="inclusive" on the identical data tightens that to 1.09-9.91, fully inside the observed range. For this dataset, zero of the 99 inclusive cut points fall outside min(data)/max(data), versus 18 for exclusive.

2. But inclusive's cut points never equal the data's actual min or max either

import statistics as st

data = list(range(1, 11))  # 1..10
incl = st.quantiles(data, n=100, method="inclusive")

print(min(data) in incl, max(data) in incl)
print(min(incl), max(incl))
False False
1.09 9.91

Measured: despite the name, method="inclusive" doesn't mean the output includes the dataset's actual minimum (1) or maximum (10) value -- neither ever appears in the 99 returned cut points, which top out at 1.09 and 9.91. "Inclusive" describes how the method maps data onto the 0-to-1 probability scale internally (treating the observed min/max as the true 0th/100th percentile), not a promise that those exact values will be among the n-1 interior cut points quantiles() actually returns.

3. The gap closes only when n matches the data size exactly

import statistics as st

data = list(range(1, 11))  # 1..10 (10 points)
incl9 = st.quantiles(data, n=9, method="inclusive")

print(incl9)
[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]

Measured: with n=9 (one less than the 10 data points), inclusive reproduces every interior data point exactly -- but 1 and 10, the actual min and max, still never appear, at any value of n. If downstream code assumes a high-resolution inclusive percentile table will contain the dataset's true minimum and maximum somewhere in the list (for example, to read off "0th percentile" by taking quantiles_list[0]), it will be reading a value close to, but never equal to, the real extreme -- append min(data) and max(data) to the list explicitly if the exact endpoints are needed.

Frequently asked questions

Does statistics.quantiles(method='inclusive') fix the out-of-range extrapolation from the default method?

Yes -- we measured quantiles(range(1,11), n=100, method='inclusive') staying fully within the data's 1-10 range (1.09 to 9.91), while the default method='exclusive' produced values from 0.11 to 10.89, 18 of which fall outside the data.

Does statistics.quantiles(method='inclusive') ever return the dataset's actual minimum or maximum?

No -- we measured the actual min (1) and max (10) never appearing among the returned cut points at n=100, n=10, or n=9. The closest values were 1.09 and 9.91 at n=100, and the gap only shrinks, it never reaches zero.

What does 'inclusive' mean in statistics.quantiles() if it doesn't include the min/max value?

It describes the probability mapping, not the output list: method='inclusive' treats the observed minimum and maximum as the literal 0th and 100th percentile internally, but quantiles() only returns the n-1 interior cut points between percentiles, never the 0th or 100th percentile itself.

How do I get the exact minimum and maximum alongside statistics.quantiles() output?

Append them explicitly -- we measured that neither method='exclusive' nor method='inclusive' ever returns the dataset's true min(data)/max(data) as one of the cut points, so code needing the exact endpoints has to add them itself rather than reading them off the quantiles list.

Written with AI assistance. Measured on 2026-10-04 with Python 3.13.5's built-in statistics module: called quantiles() with n=100 on 10 data points using both method='exclusive' (the default) and method='inclusive', and compared the returned values to the data's actual min and max. PlainHeaders is our extension; Python's statistics module is built in.