Fix ExpressionDFilter treating missing data as passing filter#2119
Open
Ayush10 wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix ExpressionDFilter treating missing data as passing filter#2119Ayush10 wants to merge 1 commit intomicrosoft:mainfrom
Ayush10 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
fillna(False) before astype("bool") in _filterSeries so that NaN
values from missing feature data (e.g. during trading halts) are
treated as not passing the filter instead of incorrectly passing.
pandas astype("bool") converts NaN to True, which caused instruments
with missing data to be included as if they satisfied the filter
expression.
Fixes microsoft#2084
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.
Summary
True(passing the filter)fillna(False)beforeastype("bool")inSeriesDFilter._filterSeriesRoot Cause
In
qlib/data/filter.pyline 145,filter_series.astype("bool")converts NaN toTruedue to pandas' casting behavior. This means instruments with missing feature data (e.g., during trading halts) incorrectly pass expression filters like$close > 2000.Fix
Test plan
ExpressionDFilter(rule_expression='$close>2000')should exclude instruments on dates where$closeis missing_toTimestampNaN handling (lines 171-172) is now consistent with this fixFixes #2084