-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
stub for statistics #1021
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
stub for statistics #1021
Conversation
stdlib/3.4/statistics.pyi
Outdated
|
||
class StatisticsError(ValueError): ... | ||
|
||
def mean(data: Iterable[_Number]) -> _Number: ... |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
stdlib/3.4/statistics.pyi
Outdated
|
||
from decimal import Decimal | ||
from fractions import Fraction | ||
from typing import Iterable, TypeVar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and Optional
https://docs.python.org/3/library/statistics.html