-
Notifications
You must be signed in to change notification settings - Fork 4k
[fix] Improve datetime handling in YahooNormalize #1959
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
base: main
Are you sure you want to change the base?
Conversation
@yang-i-hu please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Description
This PR fixes critical datetime parsing issues and deprecated pandas method warnings in the Yahoo Finance data collector. The changes address:
ValueError
andAttributeError
exceptionsfillna(method="ffill")
with modernffill()
methodKey Changes:
tz_convert(None)
vstz_localize(None)
fillna(method="ffill")
toffill()
methodutc=True
parameter to eliminate FutureWarnings about mixed timezone parsingMotivation and Context
Problem: The Yahoo data collector was failing during normalization with multiple critical errors:
unconverted data remains when parsing with format "%Y-%m-%d": " 09:30:00-04:00"
- caused by mixed datetime formats in the data'Index' object has no attribute 'tz_localize'
- caused by improper timezone handling after mixed format parsingfillna(method="ffill")
method usageRoot Cause: The original code assumed all datetime data would be in simple YYYY-MM-DD format, but Yahoo Finance data sometimes contains timezone information and mixed formats that broke the parsing logic.
Solution: Implemented robust datetime parsing with multiple fallback strategies and proper timezone handling to ensure data processing continues smoothly regardless of input datetime format.
How Has This Been Tested?
pytest qlib/tests/test_all_pipeline.py
under upper directory ofqlib
.Custom Testing Performed:
Created comprehensive test scripts to verify the fix handles various datetime formats:
Tested with actual data from the Yahoo source directory containing 10,997 CSV files
Verified fix handles edge cases:
Screenshots of Test Results (if appropriate):
Types of changes