8000 bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667) · python/cpython@48744db · GitHub
[go: up one dir, main page]

Skip to content

Commit 48744db

Browse files
authored
bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667)
Suggested by Stefan Pochmann.
1 parent ee49484 commit 48744db

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Lib/test/test_statistics.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,10 +1900,13 @@ def test_none_data(self):
19001900

19011901
def test_counter_data(self):
19021902
# Test that a Counter is treated like any other iterable.
1903-
data = collections.Counter([1, 1, 1, 2])
1904-
# Since the keys of the counter are treated as data points, not the
1905-
# counts, this should return the first mode encountered, 1
1906-
self.assertEqual(self.func(data), 1)
1903+
# We're making sure mode() first calls iter() on its input.
1904+
# The concern is that a Counter of a Counter returns the original
1905+
# unchanged rather than counting its keys.
1906+
c = collections.Counter(a=1, b=2)
1907+
# If iter() is called, mode(c) loops over the keys, ['a', 'b'],
1908+
# all the counts will be 1, and the first encountered mode is 'a'.
1909+
self.assertEqual(self.func(c), 'a')
19071910

19081911

19091912
class TestMultiMode(unittest.TestCase):

0 commit comments

Comments
 (0)
0