fix(analyser): 兼容自定义数据源返回 DataFrame 的 benchmark 行情 - #1029
Open
shuxue6662-a11y wants to merge 1 commit into
Open
Conversation
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.
Fixes #917
问题
本地自定义数据源(如 xtdata)的
history_bars返回 pandas DataFrame,而内置 bundle 数据源返回 numpy structured array。_get_one_benchmark_daily_returns中bars[1]['datetime']的行访问方式对 DataFrame 会触发KeyError: 1(DataFrame 的bars[1]是取列),导致配置 benchmark 后回测直接报错。修改
history_bars结果统一转换为 pandas DataFrame,统一使用bars['datetime'].iloc[...]访问行,兼容 numpy structured array 与 pandas DataFrame 两类数据源bars.iloc[left:],避免依赖 DataFrame 的标签索引验证
pytest tests/unittest/test_mod/test_sys_analyser.py:2 个测试全部通过pytest tests/unittest:除缺少本地 bundle 数据及环境 i18n 差异导致的既有失败外,无新增失败