Skip to content

fix: record_temp datetime extraction with ambiguous level names#2173

Open
EdenRochmanSharabi wants to merge 1 commit intomicrosoft:mainfrom
EdenRochmanSharabi:fix/record-temp-datetime-level
Open

fix: record_temp datetime extraction with ambiguous level names#2173
EdenRochmanSharabi wants to merge 1 commit intomicrosoft:mainfrom
EdenRochmanSharabi:fix/record-temp-datetime-level

Conversation

@EdenRochmanSharabi
Copy link
Copy Markdown

Summary

Fixes #1909

pred.index.get_level_values("datetime") fails when the datetime level position varies in the MultiIndex. The string-based lookup is ambiguous when level ordering differs from what is assumed.

Changes

  • qlib/workflow/record_temp.py: Replaced string-based get_level_values("datetime") with positional lookup via index.names.index("datetime") in both PortAnaRecord._generate() and MultiPassPortAnaRecord.random_init()
  • tests/test_record_temp_datetime.py: Tests covering datetime at different positions and missing datetime level

PortAnaRecord._generate and MultiPassPortAnaRecord.random_init used
pred.index.get_level_values("datetime") which assumes datetime is a
named level that pandas can resolve directly. This can fail when the
MultiIndex level ordering differs. Now we first resolve the position
with index.names.index("datetime") and pass the integer position to
get_level_values().

Fixes microsoft#1909
@EdenRochmanSharabi
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@EdenRochmanSharabi EdenRochmanSharabi changed the title Fix record_temp datetime extraction with ambiguous level names fix: record_temp datetime extraction with ambiguous level names Mar 27, 2026
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.

datetime occurs multiple times

1 participant