Repository navigation
Fix: _dts_in_same_interval("1mo") ignored year - #2780
Merged
ValueRaider merged 1 commit intoApr 25, 2026
Merged
ValueRaider merged 1 commit into
ValueRaider merged 1 commit into
Conversation
…n different years as the same interval The "1mo" branch compared only `dt1.month == dt2.month`, so e.g. (2024-12-15, 2025-12-15) returned True. The "3mo" branch already handles year differences via `year_diff`; mirror that by also requiring `dt1.year == dt2.year`. Added a test (`test_same_month_different_year`) that fails on the old logic and passes on the fix. All existing tests still pass.
Merged
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
_dts_in_same_interval(dt1, dt2, "1mo")inyfinance/utils.pycompared onlydt1.month == dt2.month, so two timestamps that share the same calendar month but are in different years were treated as falling in the same monthly interval. For example,(2024-12-15, 2025-12-15)returnedTrue.The
"3mo"branch already handles cross-year correctly (see theyear_diffcalculation just below). This PR brings the"1mo"branch in line by also requiringdt1.year == dt2.year.The function is called from
fix_Yahoo_returning_live_separate(yfinance/utils.py), which merges the last two rows of a price series when they fall in the same interval, so the old behaviour could merge rows that are actually a full year apart in 1-month-interval data.Test plan
Added
test_same_month_different_yearintests/test_utils.pycovering(Dec 2024, Dec 2025)and(Jun 2020, Jun 2025). It fails on the old logic and passes on the fix.python -m unittest tests.test_utils.TestDateIntervalCheck.test_same_month_different_year— fails before the fix, passes after.python -m unittest tests.test_utils -v— all 21 tests pass (20 pre-existing + 1 new), one pre-existing expected failure unchanged.