fix(data/filter): apply sort_index result in SeriesDFilter#2240
Open
genisis0x wants to merge 1 commit into
Open
fix(data/filter): apply sort_index result in SeriesDFilter#2240genisis0x wants to merge 1 commit into
genisis0x wants to merge 1 commit into
Conversation
_getFilterSeries called timestamp_series.sort_index() and discarded the return value. pandas Series.sort_index() returns a new sorted Series and does not sort in place, so the subsequent iteration ran over the unsorted series and could produce incorrect (timestamp, timestamp) filter ranges. Assign the sorted result back so the boundary scan sees timestamps in order, matching the intent of the existing comment. Closes microsoft#2165.
Author
|
@SunsetWolf a review when convenient would be great. One-liner in SeriesDFilter: |
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.
Description
Closes #2165.
In
qlib/data/filter.py,SeriesDFilter._getFilterSeriessorts the timestamp series but discards the result:pandas.Series.sort_index()returns a new sorted Series and does not sort in place (that would requireinplace=True). The series is therefore iterated unsorted in the loop that builds the(timestamp, timestamp)ranges, which can yield incorrect filter boundaries when the input index is not already ordered.Change
Assign the sorted result back:
timestamp_series = timestamp_series.sort_index(). This matches the intent of the existing comment and the in-order assumption of the boundary scan that follows.Testing
With an out-of-order input index, the boundary scan now iterates ascending timestamps and produces correctly ordered ranges. Already-sorted inputs are unaffected.