Skip to content

Conversation

JelleZijlstra
Copy link
Member


class StatisticsError(ValueError): ...

def mean(data: Iterable[_Number]) -> _Number: ...
Copy link
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
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
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
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 :)


from decimal import Decimal
from fractions import Fraction
from typing import Iterable, TypeVar
Copy link
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