diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2021-11-20 17:01:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-20 17:01:09 (GMT) |
commit | 48744db70ed519c1566c22bf123a0e1f5c69253f (patch) | |
tree | c791d37bd6120ab9a069cfdcbc7295e9e758336e /Lib | |
parent | ee49484c0f0d0d79e8fc40835da10b78f89ae503 (diff) | |
download | cpython-48744db70ed519c1566c22bf123a0e1f5c69253f.zip cpython-48744db70ed519c1566c22bf123a0e1f5c69253f.tar.gz cpython-48744db70ed519c1566c22bf123a0e1f5c69253f.tar.bz2 |
bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667)
Suggested by Stefan Pochmann.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_statistics.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index 5cb055c..fbc6a07 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -1900,10 +1900,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): |