summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-11-21 00:27:44 (GMT)
committerGitHub <noreply@github.com>2021-11-21 00:27:44 (GMT)
commit9841ac2da5689ff765250c1abdbf5af9d3750519 (patch)
tree076222ec25f12bbf11f4488ff1a0e4e8aa3ae6a7 /Lib
parentcf8c8788c904cce68b0ab1d39900483f50983301 (diff)
downloadcpython-9841ac2da5689ff765250c1abdbf5af9d3750519.zip
cpython-9841ac2da5689ff765250c1abdbf5af9d3750519.tar.gz
cpython-9841ac2da5689ff765250c1abdbf5af9d3750519.tar.bz2
bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667) (GH-29671)
Suggested by Stefan Pochmann. (cherry picked from commit 48744db70ed519c1566c22bf123a0e1f5c69253f) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com> Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_statistics.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py
index adccfad..2853b1b 100644
--- a/Lib/test/test_statistics.py
+++ b/Lib/test/test_statistics.py
@@ -1897,10 +1897,13 @@ class TestMode(NumericTestCase, AverageMixin, UnivariateTypeMixin):
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 return the first mode encountered, 1
- self.assertEqual(self.func(data), 1)
+ # We're making sure mode() first calls iter() on its input.
+ # The concern is that a Counter of a Counter returns the original
+ # unchanged rather than counting its keys.
+ c = collections.Counter(a=1, b=2)
+ # If iter() is called, mode(c) loops over the keys, ['a', 'b'],
+ # all the counts will be 1, and the first encountered mode is 'a'.
+ self.assertEqual(self.func(c), 'a')
class TestMultiMode(unittest.TestCase):