Skip to content

stub for statistics#1021

Merged
ambv merged 3 commits into
python:masterfrom
JelleZijlstra:statistics
Mar 18, 2017
Merged

stub for statistics#1021
ambv merged 3 commits into
python:masterfrom
JelleZijlstra:statistics

Conversation

@JelleZijlstra

Copy link
Copy Markdown
Member

Comment thread stdlib/3.4/statistics.pyi

class StatisticsError(ValueError): ...

def mean(data: Iterable[_Number]) -> _Number: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mean of ints returns a float.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yes. I wonder if we could just drop int from the typevar and rely on automatic int-to-float promotion.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that should work. It would lie slightly in that something like statistics.median([1, 2, 3]) will in fact return int but mypy would infer it to return float, but that seems harmless.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, median for ints returns a float if the number of elements is even. So I think we're good :)

Comment thread stdlib/3.4/statistics.pyi Outdated

from decimal import Decimal
from fractions import Fraction
from typing import Iterable, TypeVar

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and Optional

@ambv ambv merged commit 5898d75 into python:master Mar 18, 2017
@JelleZijlstra JelleZijlstra deleted the statistics branch March 18, 2017 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants