exponential_moving_average returns an incorrect second value when window_size=1
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 88/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
從 financial/exponential_moving_average.py 開始,使用 window_size=1 執行已回報的重現。檢查 i <= window_size 附近的初始化分支,並查看現有的 doctest 以了解上下文。完成的標準是:對於該輸入,exponential_moving_average 回傳 [10.0, 20.0, 30.0],同時保留現有的 window_size=3 行為。
由索引模型根據 Issue 內容生成。
描述
Repository commit
7f81fcd68c195ce71534de09d1b69d2b61665902
Python version (python --version)
Python 3.14.7
Dependencies version (pip freeze)
No third-party dependencies are required for this reproduction; the function uses only the Python standard library.
Expected behavior
For window_size=1, the documented smoothing factor is:
alpha = 2 / (1 + window_size) = 1
Therefore, the documented recurrence should return each input value unchanged.
For input [10.0, 20.0, 30.0], the expected output is:
[10.0, 20.0, 30.0]
Actual behavior
The function returns [10.0, 15.0, 30.0], so the second value is incorrect.
Reproduction from the repository root:
from financial.exponential_moving_average import exponential_moving_average
actual = list(
exponential_moving_average(iter([10.0, 20.0, 30.0]), window_size=1)
)
print(actual)
# [10.0, 15.0, 30.0]
assert actual == [10.0, 20.0, 30.0]
# AssertionError
The initialization branch uses if i <= window_size. At i=1 and window_size=1, it calculates (moving_average + stock_price) * 0.5, producing 15.0 instead of applying alpha=1.
The existing doctest uses window_size=3 and passes, but does not cover this case.
The unmodified source file at the reported commit was tested with Python 3.14.7.
- 主要語言
- Python
- 星號
- 225k
- 分支
- 51.1k
- 平均合併
- 16 小時 12 分鐘
- 30 天內合併 PR
- 180
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TheAlgorithms/Python 的其他 Issue
-
enhancement good first issue hacktoberfest tracking issue
難度 2/5 1-3 小時 新手友好度 74/100
TheAlgorithms/Python#15234 · 91 則留言 ·
維護者通常 1 天內回覆
-
TheAlgorithms/python_maintainers: Call for help in preparing for Hacktoberfest 2026可能已有人在做 @AnupKumarPanwar 於 12 天前認領。 未關閉help wanted
TheAlgorithms/Python#15351 · 已指派 2 人 ·
維護者通常 1 天內回覆
-
enhancement
難度 4/5 3-5 天 新手友好度 45/100
TheAlgorithms/Python#15337 · 14 則留言 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
TheAlgorithms/Python#15310 · 23 則留言 ·
維護者通常 1 天內回覆
-
hacktoberfest help wanted tracking issue
難度 4/5 3-5 天 新手友好度 42/100
TheAlgorithms/Python#15187 · 8 則留言 ·
維護者通常 1 天內回覆
查看 TheAlgorithms/Python 的全部 Issue
相似的 Issue
-
namespace operations
難度 1/5 1 小時以內 新手友好度 82/100
EclipseFdn/open-vsx.org#13573 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
collective/icalendar#1854 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
rancher/rancher-ai-agent#412 ·
維護者通常 6 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
TUDelftGeodesy/DePSI#134 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
HenriquesLab/rxiv-maker#335 ·