Closed
Description
Bug report
Bug description:
The implementation of statistics.geometric_mean
using logarithms requires that all input values must be positive. However, a real geometric mean is defined for all sets of non-negative real values. The geo mean of any set of numbers containing zero is itself zero.
from statistics import geometric_mean
geometric_mean([1.0, 2.0, 0.0])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/milthorpe/miniconda3/lib/python3.11/statistics.py", line 489, in geometric_mean
raise StatisticsError('geometric mean requires a non-empty dataset '
statistics.StatisticsError: geometric mean requires a non-empty dataset containing positive numbers
I believe geometric_mean
should return 0 if any of the input values are zero. (It should continue to return a StatisticsError
if any of the input values are negative.)
CPython versions tested on:
3.11
Operating systems tested on:
Linux