Skip to content

feat: configurable entity column in DataFeed - #7

Merged
stefan-jansen merged 1 commit into
mainfrom
fix/datafeed-entity-column
Mar 14, 2026
Merged

feat: configurable entity column in DataFeed#7
stefan-jansen merged 1 commit into
mainfrom
fix/datafeed-entity-column

Conversation

@stefan-jansen

Copy link
Copy Markdown
Contributor

Summary

  • DataFeed now auto-detects the entity identifier column from prices/signals data
  • Detection order: symbol > asset > product > ticker
  • New entity_col keyword parameter for explicit override
  • No more hardcoded "asset" column name — existing code with asset column still works

Why

The book codebase uses symbol as the canonical entity column (and product for CME futures). DataFeed hardcoded asset, requiring callers to rename columns before passing data. This was fragile and got lost on every uv sync.

Test plan

  • All existing DataFeed tests pass (backward compat with asset column)
  • New tests: auto-detect symbol, asset, product; explicit override; error cases; signals with symbol

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 14, 2026 03:13
@stefan-jansen
stefan-jansen merged commit dd6a453 into main Mar 14, 2026
5 of 6 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the DataFeed class's entity identifier column configurable instead of hardcoding "asset". It adds auto-detection (checking symbol > asset > product > ticker in order) and an explicit entity_col keyword parameter for override.

Changes:

  • Added ENTITY_COL_CANDIDATES class constant and _resolve_entity_col classmethod to auto-detect or validate the entity column
  • Added entity_col keyword-only parameter to DataFeed.__init__ and replaced all hardcoded "asset" references with the resolved _entity_col
  • Added comprehensive tests covering auto-detection, explicit override, error cases, and signals integration

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/ml4t/backtest/datafeed.py Add entity column auto-detection and entity_col parameter; replace hardcoded "asset" with dynamic _entity_col
tests/test_datafeed_memory.py Add TestDataFeedEntityColumn test class covering auto-detect, priority, explicit override, and error cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ml4t/backtest/datafeed.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants