Skip to content

Conversation

@AlexWaygood
Copy link
Member

Providing an int or a float for the interval parameter appears to work, regardless of what weird and whacky inputs you supply for the data parameter:

>>> import statistics
>>> statistics.median_grouped([1, 5, 6, 8, 10], interval=2.0)
6.0
>>> statistics.median_grouped([1, 5, 6, 8, 10], interval=2)
6.0
>>> statistics.median_grouped([1.5, 5, 6, 8, 10], interval=2.0)
6.0
>>> from fractions import Fraction
>>> statistics.median_grouped([1.5, Fraction(5, 5), 6, 8, 10], interval=2.0)
6.0
>>> statistics.median_grouped([Fraction(1, 2), Fraction(4, 5), Fraction(2, 3)], interval=Fraction(1, 2))
0.6666666666666667
>>> from decimal import Decimal
>>> statistics.median_grouped([Decimal("0.5"), Decimal("0.7")], interval=4)
-1.3

(The union return is still required: if you supply a sequence with length exactly 1 to the data parameter, the sole member of the sequence is returned as-is, without any coercion to float.)

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

Seems like we messed something up in mypy-primer.

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Jan 31, 2023

Seems like we messed something up in mypy-primer.

The diffs were well formatted in #9629, so I don't think this can be due to any changes we've made over at typeshed. Something else must have changed.

But yeah, the same thing happened in #9635 and #9634.

@JelleZijlstra
Copy link
Member

hauntsaninja/mypy_primer@bb842b5 should fix.

@JelleZijlstra
Copy link
Member

@hauntsaninja fyi

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 510bd46 into main Feb 1, 2023
@JelleZijlstra JelleZijlstra deleted the median-grouped branch February 1, 2023 01:29
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