Skip to content

fix: incorrect index implementation in FileCalendarStorage#2195

Merged
SunsetWolf merged 1 commit intomicrosoft:mainfrom
Srujanrana07:fix-calendar-index-bug
Apr 21, 2026
Merged

fix: incorrect index implementation in FileCalendarStorage#2195
SunsetWolf merged 1 commit intomicrosoft:mainfrom
Srujanrana07:fix-calendar-index-bug

Conversation

@Srujanrana07
Copy link
Copy Markdown
Contributor

@Srujanrana07 Srujanrana07 commented Apr 19, 2026

Description

Fixes incorrect behavior in FileCalendarStorage.index() where a value
present in the calendar could still raise an IndexError.

The previous implementation used NumPy comparison on a Python list,
which resulted in incorrect boolean evaluation and failure to locate
existing values.

This change replaces it with Python’s built-in list.index() method,
ensuring correct lookup behavior.


Motivation and Context

Fixes #2192

The current implementation:

np.argwhere(calendar == value)

fails because calendar is a Python list, and list == value returns
a single boolean instead of an element-wise comparison.

This leads to:

  • Incorrect IndexError even when value exists
  • Wrong exception type (should be ValueError if not found)

This fix aligns behavior with Python's standard list.index().

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • Verified logic manually for correct index lookup behavior

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

@SunsetWolf SunsetWolf changed the title Fix incorrect index implementation in FileCalendarStorage fix: incorrect index implementation in FileCalendarStorage Apr 21, 2026
@SunsetWolf
Copy link
Copy Markdown
Collaborator

Hi, @Srujanrana07 , Thanks for the contribution! Really appreciate your work on this.

@SunsetWolf SunsetWolf merged commit 7ccf3f7 into microsoft:main Apr 21, 2026
77 of 78 checks passed
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.

FileCalendarStorage.index() 方法存在严重缺陷

2 participants