Repository navigation
Fix DeprecationWarning on every import: Timedelta generic unit - #2357
Open
Krishna Anubhav (heykav) wants to merge 1 commit into
Open
Krishna Anubhav (heykav) wants to merge 1 commit into
Krishna Anubhav (heykav) wants to merge 1 commit into
Conversation
qlib/constant.py builds ONE_DAY/ONE_MIN/EPS_T via pd.Timedelta("1day")
/("1min")/("1s") string parsing. On current pandas, that path hits
NumPy's deprecated 'generic' timedelta unit and warns - which fires on
every single import of qlib, since these are module-level constants
evaluated at import time, and 'will raise an error in the future' per
pandas's own warning text.
pd.Timedelta(<n>, <unit>) (the two-argument form) takes pandas's
explicit-unit construction path instead, producing byte-identical
values without the deprecated path. Checked for the same
string-parsing pattern elsewhere in qlib/ - this was the only site.
Verified: import qlib.constant with DeprecationWarning promoted to an
error raises before the fix, is clean after; ONE_DAY/ONE_MIN/EPS_T
values unchanged (1 days 00:00:00 / 0 days 00:01:00 / 0 days
00:00:01); tests/test_register_ops.py and
tests/test_structured_cov_estimator.py still 6/6.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
qlib/constant.pybuildsONE_DAY/ONE_MIN/EPS_Tviapd.Timedelta("1day")/("1min")/("1s")string parsing. On current pandas, that path hits NumPy's deprecated "generic" timedelta unit and warns:Since these are module-level constants evaluated at import time, this fires on every single import of qlib — and per pandas's own warning text, it "will raise an error in the future," not just warn indefinitely.
Fix
pd.Timedelta(<n>, <unit>)(the two-argument form) takes pandas's explicit-unit construction path instead of string parsing, producing byte-identical values without hitting the deprecated path:Checked for the same string-parsing pattern (
Timedelta("1day")etc.) elsewhere inqlib/— this was the only site.Verification
python -W error::DeprecationWarning -c "import qlib.constant"raises before this fix, is clean after.ONE_DAY/ONE_MIN/EPS_Tvalues unchanged:1 days 00:00:00/0 days 00:01:00/0 days 00:00:01.tests/test_register_ops.py+tests/test_structured_cov_estimator.py: 6/6, same as before the change.