summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_statistics.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2014-02-08 09:44:16 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2014-02-08 09:44:16 (GMT)
commitbfd68bf4ac6661bf0fab51178583bee88840a8e6 (patch)
tree25150831444976e4c64ac363fee3645861612d90 /Lib/test/test_statistics.py
parentec1c8097c18c5fadaf74ff25c9bc88bf661e3222 (diff)
downloadcpython-bfd68bf4ac6661bf0fab51178583bee88840a8e6.zip
cpython-bfd68bf4ac6661bf0fab51178583bee88840a8e6.tar.gz
cpython-bfd68bf4ac6661bf0fab51178583bee88840a8e6.tar.bz2
Issue #20478: avoid special casing Counter in statistics
Passing Counter objects to the Counter constructor is special cased, going through iter() firsts ensures they are handled the same way as any other iterable. (Committing on Steven's behalf as I don't believe his SSH key is registered yet)
Diffstat (limited to 'Lib/test/test_statistics.py')
-rw-r--r--Lib/test/test_statistics.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index 3d30d88..6db821f 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -1355,6 +1355,14 @@ class TestMode(NumericTestCase, AverageMixin, UnivariateTypeMixin):
# collections.Counter, which accepts None and returns an empty dict.
self.assertRaises(TypeError, self.func, None)
+ def test_counter_data(self):
+ # Test that a Counter is treated like any other iterable.
+ data = collections.Counter([1, 1, 1, 2])
+ # Since the keys of the counter are treated as data points, not the
+ # counts, this should raise.
+ self.assertRaises(statistics.StatisticsError, self.func, data)
+
+
# === Tests for variances and standard deviations ===