BUG: Fixed DataFrame.resample() generating errors when bin edges fall on DST transitions#65314
Open
presidentjacob wants to merge 23 commits intopandas-dev:mainfrom
Open
BUG: Fixed DataFrame.resample() generating errors when bin edges fall on DST transitions#65314presidentjacob wants to merge 23 commits intopandas-dev:mainfrom
presidentjacob wants to merge 23 commits intopandas-dev:mainfrom
Conversation
…pandas into bugfix/dataframe
Added an additional test case as check edge case, as 1D requires N+1 bins to be made, so April 24th -> April 25th will also generated April 26th bin
Contributor
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.
Problem Description
DataFrame.resample() on DataFrames where edges exist in DST gaps would cause
NonExistentTimeErrorinstead of handling DST gracefully and pushing time forward by 1 hour.Root Cause
The resampling bin-edge construction assumed calendar-day anchors like local midnight always exist in the timezone of the target. Around DST transitions where midnight is a non-existent local time (such as Africa/Cairo on April 26th, where 00:00:00 does not exist), the assumption causes failures. Edge generation produced invalid boundaries.
Fix
Fix strips the timezone before normalizing to avoid hitting the nonexistent local time. The returned tz-naive timestamps are re-localized by the
date_rangecall in_get_time_binsvianonexistent="shift_forward"In
_get_timestamp_range_edgesinpandas/core/resample.py:DataFrame.resample()fails across DST transitions withNonExistentTimeErrorin timezone-aware data #62601doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.AGENTS.md.