This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jfine2358
Recipients jfine2358
Date 2019-01-09.11:46:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1547034372.58.0.0557058004142.issue35698@roundup.psfhosted.org>
In-reply-to
Content
When len(data) is odd, median returns the average of the two middle values. This average is computed using
        i = n//2
        return (data[i - 1] + data[i])/2

This results in the following behaviour

>>> from fractions import Fraction
>>> from statistics import median
>>> F1 = Fraction(1, 1)

>>> median([1])
1
>>> median([1, 1]) # Example 1.
1.0

>>> median([F1])
Fraction(1, 1)
>>> median([F1, F1])
Fraction(1, 1)

>>> median([2, 2, 1, F1]) # Example 2.
Fraction(3, 2)

>>> median([2, 2, F1, 1]) # Example 3.
1.5

Perhaps, when len(data) is odd, it would be better to test the two middle values for equality. This would resolve Example 1. It would not help with Examples 2 and 3, which might not have a satisfactory solution.

See also issue 33084.
History
Date User Action Args
2019-01-09 11:46:14jfine2358setrecipients: + jfine2358
2019-01-09 11:46:12jfine2358setmessageid: <1547034372.58.0.0557058004142.issue35698@roundup.psfhosted.org>
2019-01-09 11:46:12jfine2358linkissue35698 messages
2019-01-09 11:46:12jfine2358create