8000 [3.10] bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667) by miss-islington · Pull Request #29671 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.10] bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667) #29671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2021
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
11 changes: 7 additions & 4 deletions Lib/test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,10 +1897,13 @@ def test_none_data(self):

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):
Expand Down
0