Bug report
Bug description:
In Lib/statistics.py, The kde() and kde_random() functions only validate the first element in the data argument passed. It accepts the following:
>>> import statistics
>>> data = [1.5, "bad", 2.4]
>>> f = statistics.kde(data,h=0.5)
>>> f
<function kde.<locals>.pdf at 0x000001905213A3E0>
>>> print(f(1))
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
print(f(1))
File "E:\Python\Lib\statistics.py", line 980, in pdf
return sum(K((x - x_i) / h) for x_i in data) / (n * h)
File "E:\Python\Lib\statistics.py", line 980, in <genexpr>
return sum(K((x - x_i) / h) for x_i in data) / (n * h)
TypeError: unsupported operand type(s) for -: 'int' and 'str'
The code in the module , only validates the first data element:
if not isinstance(data[0], (int, float)):
raise TypeError('Data sequence must contain ints or floats')
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
In
Lib/statistics.py, The kde() and kde_random() functions only validate the first element in the data argument passed. It accepts the following:The code in the module , only validates the first data element:
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Linked PRs