Skip to content
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

statistics.mean of bools #71100

Closed
PeterNorvig mannequin opened this issue May 2, 2016 · 2 comments
Closed

statistics.mean of bools #71100

PeterNorvig mannequin opened this issue May 2, 2016 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@PeterNorvig
Copy link
Mannequin

PeterNorvig mannequin commented May 2, 2016

BPO 26913
Nosy @stevendaprano, @bitdancer
Superseder
  • bpo-24068: statistics module - incorrect results with boolean input
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-05-02.21:41:14.334>
    created_at = <Date 2016-05-02.20:59:11.028>
    labels = ['type-bug', 'library']
    title = 'statistics.mean of bools'
    updated_at = <Date 2016-05-02.21:41:14.332>
    user = 'https://bugs.python.org/PeterNorvig'

    bugs.python.org fields:

    activity = <Date 2016-05-02.21:41:14.332>
    actor = 'r.david.murray'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-05-02.21:41:14.334>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2016-05-02.20:59:11.028>
    creator = 'Peter.Norvig'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 26913
    keywords = []
    message_count = 2.0
    messages = ['264670', '264675']
    nosy_count = 3.0
    nosy_names = ['steven.daprano', 'r.david.murray', 'Peter.Norvig']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '24068'
    type = 'behavior'
    url = 'https://bugs.python.org/issue26913'
    versions = ['Python 3.5', 'Python 3.6']

    @PeterNorvig
    Copy link
    Mannequin Author

    PeterNorvig mannequin commented May 2, 2016

    mean([True, True, True, False]) should be 0.75, but it returns 0.25.

    The fix is to change _sum so that when the type is bool, the result should be coerced to int, not bool.

    Why it is important for statistics.mean to work with bools:
    It is natural to say something like
    mean(x > threshold for x in data)
    and expect to get the percentage of items in data that are above threshold.

    @PeterNorvig PeterNorvig mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 2, 2016
    @bitdancer
    Copy link
    Member

    Already fixed: bpo-24068.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant