statistics.kde has inconsistent and counterintuitive caching behaviour
未关闭
@rhettinger 已经在做这个了。
开始于 2026年8月6日。
docs
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
The author appears to be trying to support this pattern:
data = [1, 2, 3]
f = kde(data, h=1)
data.append(4) # length changed
f(2)
In that case len(data) != n becomes true and the sorted sample is rebuilt.
However, this pattern is implemented inconsistently, and does not check value changes, only length changes.
import statistics
data = [1, 2, 3]
f = statistics.kde(data, h=1.0, kernel='triangular')
z = f(1.5)
print(z)
data[0] = 5
print(f(1.5))
data.pop()
print(f(1.5))
data = [1, 2, 3]
f = statistics.kde(data, h=1.0, kernel='normal')
z = f(1.5)
print(z)
data[0] = 5
print(f(1.5))
data.pop()
print(f(1.5))
output:
0.3333333333333333
0.3333333333333333
0.25
vs.
0.2778827497314969
0.16081853504174567
0.17646900472967264
CPython versions tested on:
3.13
Operating systems tested on:
Other
Linked PRs
- gh-155034
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
评估
这个 Issue 还没有评估数据。