New submission from Stefan Pochmann <stefan.pochm...@gmail.com>:

This test:

    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)

If the mode() code *were* wrong this way (used Counter(data) instead of 
Counter(iter(data))), then the test wouldn't detect it, as mode() would still 
return 1. The test data should be [1, 2, 2, 2] instead, in which case such 
wrong mode() would return 2.

It used to be correct but wasn't adjusted correctly when mode() switched from 
raising an error for multiple modes to returning the first. The old code was:

    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 raise.
        self.assertRaises(statistics.StatisticsError, self.func, data)

----------
components: Tests
messages: 406642
nosy: Stefan Pochmann
priority: normal
severity: normal
status: open
title: statistics.mode test doesn't test what it claims to
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45852>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to