Fix generic-unit timedelta DeprecationWarning for sub-day intervals (#2882)#2891
Open
DogInfantry wants to merge 1 commit into
Open
Fix generic-unit timedelta DeprecationWarning for sub-day intervals (#2882)#2891DogInfantry wants to merge 1 commit into
DogInfantry wants to merge 1 commit into
Conversation
pd.Timedelta() was called with bare interval strings (e.g. "1h", "30m"), which numpy>=2.5 flags with 'The generic unit for NumPy timedelta is deprecated'. Parse minute/hour intervals with explicit units in _interval_to_timedelta and route _dts_in_same_interval through it so both warning sites are covered. Fixes ranaroussi#2882 Co-Authored-By: Claude Opus 4.8 <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.
@
Summary
Fixes #2882.
_interval_to_timedeltafell through to_pd.Timedelta(interval)for sub-day intervals ("1m","30m","1h", …). Passing a bare interval string makes numpy >= 2.5 emit:flooding the console on any intraday download and set to become a hard error in a future numpy/pandas release.
Changes
yfinance/utils.py: parse minute intervals asTimedelta(minutes=...)and hour intervals asTimedelta(hours=...)with explicit units in_interval_to_timedelta._dts_in_same_interval(was calling_pd.Timedelta(interval)inline), through_interval_to_timedeltaso both reported lines (484 and 667 in the issue) are covered by one fix.pd.Timedelta("1m")already parsed as 1 minute); only the code path changes.Tests
Added to
tests/test_utils.py:test_no_generic_timedelta_deprecation_warning- asserts no generic-unitDeprecationWarningfor1m/2m/5m/15m/30m/60m/90m/1h.test_interval_to_timedelta_values- locks the parsed values.python -m pytest tests/test_utils.py→ 22 passed, 1 xfailed (pre-existing).Note: my local env has numpy 2.4.6 (< 2.5), so the warning does not fire there; the fix removes the bare-string path that warns on numpy >= 2.5 and the new test is version-agnostic.
@