[issue35698] Division by 2 in statistics.median

2019-01-10 Thread Brett Cannon
Change by Brett Cannon : -- nosy: +steven.daprano ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mai

[issue35698] Division by 2 in statistics.median

2019-01-10 Thread Jonathan Fine
Jonathan Fine added the comment: It might be better in my sample code to write isinstance(p, int) instead of type(p) == int This would fix Rémi's example. (I wanted to avoid thinking about (False // True).) For median([1, 1]), I am not claiming that 1.0 is wrong and 1 is right. I'm not

[issue35698] Division by 2 in statistics.median

2019-01-10 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: This does not do what you want: >>> class MyInt(int): pass >>> wibble(MyInt(4), MyInt(2)) 2.0 and a patch is only needed if something is broken. I'm with vstinner of the opinion that nothing is broken and vote to close this issue. --

[issue35698] Division by 2 in statistics.median

2019-01-10 Thread Jonathan Fine
Jonathan Fine added the comment: Here's the essence of a patch. Suppose the input is Python integers, and the output is a mathematical integer. In this case we can make the output a Python integer by using the helper function >>> def wibble(p, q): ... if type(p) == type(q) == int and p%

[issue35698] Division by 2 in statistics.median

2019-01-10 Thread STINNER Victor
STINNER Victor added the comment: I suggest to close the issue as "not a bug". IMHO statistics.median() respects the defintion of the mathematical median function. -- ___ Python tracker

[issue35698] Division by 2 in statistics.median

2019-01-10 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: > As a secondary school student, knowing the definition of median, I might > expect the value to be 2, for any n > 0. The secondary school student would be wrong, wouldn't he? The median of a set is not expected to be a part of the set. Especially for ints sin

[issue35698] Division by 2 in statistics.median

2019-01-10 Thread Jonathan Fine
Jonathan Fine added the comment: I read PEP 450 as saying that statistics.py can be used by "any secondary school student". This is not true for most Python libraries. In this context, the difference between a float and an int is important. Consider statistics.median([2] * n) As a second

[issue35698] Division by 2 in statistics.median

2019-01-09 Thread STINNER Victor
STINNER Victor added the comment: > vstinner: The problem isn't the averaging, it's the type inconsistency. >>> type(statistics.median([1])) >>> type(statistics.median([1,2])) Which consistency? :-) -- ___ Python tracker

[issue35698] Division by 2 in statistics.median

2019-01-09 Thread Josh Rosenberg
Josh Rosenberg added the comment: vstinner: The problem isn't the averaging, it's the type inconsistency. In both examples (median([1]), median([1, 1])), the median is unambiguously 1 (no actual average is needed; the values are identical), yet it gets converted to 1.0 only in the latter cas

[issue35698] Division by 2 in statistics.median

2019-01-09 Thread Rémi Lapeyre
Rémi Lapeyre added the comment: What do you think median([1, 1.0]) should return? -- nosy: +remi.lapeyre ___ Python tracker ___ ___

[issue35698] Division by 2 in statistics.median

2019-01-09 Thread STINNER Victor
STINNER Victor added the comment: > When len(data) is odd, median returns the average of the two middle values. I'm not sure that I understand your issue. Do you consider that it's a bug? It's part of the definition of the median function, no? https://en.wikipedia.org/wiki/Median#Finite_set_o

[issue35698] Division by 2 in statistics.median

2019-01-09 Thread Jonathan Fine
New submission from Jonathan Fine : 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 statisti