Skip to content

Fix issues found by Sourcery review - #399

Open
im47cn-bot wants to merge 1 commit into
shiyu-coder:masterfrom
im47cn-bot:sourcery-fixes
Open

im47cn-bot wants to merge 1 commit into
shiyu-coder:masterfrom
im47cn-bot:sourcery-fixes

Conversation

@im47cn-bot

Copy link
Copy Markdown

修复摘要

Sourcery 扫描发现的问题已全部修复(54 issues:44 自动 + 10 手工)。

自动修复(merge-duplicate-blocks / simplify-if / swap-if-expression / use-named-expression 等)

  • finetune/qlib_test.py、finetune_csv/config_loader.py、finetune_csv/train_sequential.py、model/__init__.py、model/module.py、webui/run.py 等 11 文件
  • model/kronos.py: sample_from_logits 嵌套 if 合并、ran = trange if verbose else range、any(col not in ...) 替代 not all(col in ...)

手工重构(rule: low-code-quality,全部行为等价)

文件 重构
finetune/train_predictor.py train_model 拆为 _train_one_epoch/_validate/_log_epoch_summary
finetune/train_tokenizer.py train_model 拆为 _train_one_epoch/_accumulate_gradients/_validate/_log_epoch_summary
finetune_csv/finetune_base_model.py train_model 拆为 6 个 helper(_prepare_epoch/_train_one_epoch/_validate_model/_reduce_epoch_metrics/_log_epoch_summary/_save_best_if_improved)
finetune_csv/finetune_tokenizer.py train_tokenizer 拆为 5 个 helper(梯度累积提取 _accumulate_gradients)
model/kronos.py predict_batch 拆为 _prepare_batch_series/_build_batch_pred_dfs
webui/app.py create_prediction_chart 与 predict 拆为 13 个 helper

测试规则处理

  • tests/test_kronos_regression.py: MSE 采样循环提取为模块级 _compute_mse_values(消除 no-loop-in-tests)
  • 保留 3 处 no-conditionals-in-tests:均为数据前提守卫(数据不足时 raise ValueError 而非静默失败),属合法测试前提检查,非断言条件

验证

  • python3 -m py_compile 全部 23 个跟踪文件通过
  • sourcery review 仅剩上述 3 处有意保留的守卫
  • pytest tests/ 4 个回归测试全部通过
Apply Sourcery fixes across finetune, finetune_csv, model and webui:
- Auto-fixed: merge-duplicate-blocks, simplify-if, swap-if-expression, use-named-expression, any() over not-all(), etc.
- Manual low-code-quality refactors (behavior-preserving): train_model/train_tokenizer split into epoch/validate/summary helpers; kronos.py predict_batch split; webui app.py create_prediction_chart and predict split
- tests: MSE sampling loop extracted to _compute_mse_values; 3 data-guard conditionals kept intentionally

Verification: py_compile all files, sourcery review zero issues except 3 kept guards, pytest 4 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants