Fix pytrader data loading and Backtrader conversion - #120
Open
ai-yang wants to merge 2 commits into
Open
Conversation
|
ai-yang
marked this pull request as ready for review
July 31, 2026 15:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
DataUtil.to_backtrader_dataframe(self, df)的非法方法签名。code列。benchmarks列表在不同DataUtil实例之间共享。Motivation and Context
当前
main中的方法签名会导致pytrader/data/data_utils.py在 Python 3 下无法解析。仅修正签名后,数据列选择还会删除随后仍被访问的code列;恢复该列后,代码索引又与load_data的日期切片约定冲突。这组问题会阻断策略数据加载,或者使多标的日期区间过滤得到错误结果。非法签名修复后,SonarCloud 还暴露了原有的可变默认参数问题:修改一个默认实例的
benchmarks会污染后续实例。Related issue: none. 上游当前限制此账号创建 Issue(GitHub API 返回 403),因此复现、根因和测试信息完整记录在本 PR 中。
How Has This Been Tested?
pytest -q tests/test_data_utils.py:4 passedpython -m unittest -q tests.test_data_utils:连续 3 次通过,每次 4 testspython -m py_compile pytrader/data/data_utils.py tests/test_data_utils.pyflake8 --select=E9,F63,F7,F82 pytrader/data/data_utils.py tests/test_data_utils.pygit diff --check origin/main...HEAD全仓
compileall当前还会被独立的pyfutures/futuresDemo.pyPython 2print语法问题阻塞;该错误不由本 PR 引入,并已拆分为另一独立修复。未运行模板中提到的裸全仓 pipeline 测试:当前仓库部分测试包含联网、真实邮件、交易入口或无限循环风险。本 PR 的回归测试全部离线执行。
Types of changes