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

Skip to content

Commit 9841ac2

Browse files
bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667) (GH-29671)
Suggested by Stefan Pochmann. (cherry picked from commit 48744db) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com> Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
1 parent cf8c878 commit 9841ac2

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
@@ -1897,10 +1897,13 @@ def test_none_data(self):
18971897

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

19051908

19061909
class TestMultiMode(unittest.TestCase):

0 commit comments

Comments
 (0)
0