Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 23 Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,20 @@ def test_specific_cases(self):
result = quantiles(map(datatype, data), n=n)
self.assertTrue(all(type(x) == datatype) for x in result)
self.assertEqual(result, list(map(datatype, expected)))
# Quantiles should be idempotent
if len(expected) >= 2:
self.assertEqual(quantiles(expected, n=n), expected)
# Cross-check against other methods
if len(data) >= n:
# After end caps are added, method='inclusive' should
# give the same result as method='exclusive' whenever
# there are more data points than desired cut points.
padded_data = [min(data) - 1000] + data + [max(data) + 1000]
self.assertEqual(
quantiles(data, n=n),
quantiles(padded_data, n=n, method='inclusive'),
(n, data),
)
# Invariant under tranlation and scaling
def f(x):
return 3.5 * x - 1234.675
Expand Down Expand Up @@ -2219,6 +2233,15 @@ def f(x):
actual = quantiles(statistics.NormalDist(), n=n, method="inclusive")
self.assertTrue(all(math.isclose(e, a, abs_tol=0.0001)
for e, a in zip(expected, actual)))
# Whenever n is smaller than the number of data points, running
# method='inclusive' should give the same result as method='exclusive'
# after the two included extreme points are removed.
data = [random.randrange(10_000) for i in range(501)]
actual = quantiles(data, n=32, method='inclusive')
data.remove(min(data))
data.remove(max(data))
expected = quantiles(data, n=32)
self.assertEqual(expected, actual)

def test_equal_inputs(self):
quantiles = statistics.quantiles
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.