-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TSDataSampler Slicing Bug #1716 #1803
Merged
Merged
Conversation
This file contains 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
github-actions
bot
added
the
waiting for triage
Cannot auto-triage, wait for triage.
label
Jun 3, 2024
@microsoft-github-policy-service agree |
with Simplified Implementation
Could you please fix the CI errors? |
The CI errors were due to pylint formatting issues, but I've fixed them now. |
Thanks for your great efforts! |
SunsetWolf
added
bug
Something isn't working
and removed
waiting for triage
Cannot auto-triage, wait for triage.
labels
Dec 23, 2024
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.
Title: Fix TSDataSampler Slicing Bug #1716
Description
I have optimized the mechanism for reading data from
data_arr
in the__getitem__
method:__getitem__
of TSDataSampler: get nothing when slicing instead of indexing #1716, I adopted a straightforward approach to circumvent the problem: setself.nan_idx
tolen(self.data_arr) - 1
instead of-1
.Motivation and Context
Related Issue Link
The
__getitem__
function of TSDataSampler generally operates without issue, yet in certain scenarios, particularly whenstep_len
is significant andnan
must be added prior tostart
, it may inadvertently sample an empty list, which is erroneous.Consider the following code snippet as an example:
The expected outcome should be an array with
nan
as the initial element followed by numerical values.However, the actual result is an empty list, as depicted in the following image:
Mechanism of the Error
How did this issue arise? It stems from the fact that the
dataframe
data has been stored in anndarray
(variable name:data_arr
) in the order of 'instrument, time', and thus a set ofindicies
is generated during the fetch. The logical error occurs whenstep_len
is large, and the count from the current processing position back tostart
requiresnan
supplementation (as shown in the following image):These
nan
values are then converted to -1 during subsequent processing (as shown in the following image) becauseself.nan_idx
is hardcoded as -1:Therefore, the error occurs when there are several -1s at the beginning, causing the slice to become
[-1, index of the last value to be fetched]
. In cases requiring padding, this index is typically small, leading to the retrieval of an empty list, which is the error reported in the issue.My Modification Approach
Since the error always occurs at the beginning with
nan
, theindicies[0]
must beself.nan_idx
, which is hardcoded to-1
. For this scenario, it causes issues with the retrievedslices
. After examining, I found thatself.nan_idx
is only called once in this context. Therefore, following the original author's intention, I changedself.nan_idx
tolen(self.data_arr) - 1
. This solution not only addresses the problem but also avoids reducing code readability.How Has This Been Tested?
pytest qlib/tests/test_all_pipeline.py
under the upper directory ofqlib
.My test scripts are located in
tests/data_mid_layer_tests/test_dataset.py
.TestTSDataSampler
includes two test contents:__getitem__
of TSDataSampler: get nothing when slicing instead of indexing #1716 (i.e., partial sampling results in an empty list).nan
padding and is directly fetched, the test result should be the direct retrieval of the first value.Screenshots of Test Results (if appropriate):
Pipeline test:
Your own tests:
Types of changes