Repository navigation
Conversation
…teOffset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
When users pass a
DateOffsetsuch asDateOffset(months=1)toresample, or toGrouper(freq=...), they getNotImplementedError: Prefix not defined, even though theresampledocs sayrulecan be aDateOffset.Cause:
rule_code, a short name such as"ME"(month end) or"W"(weekly).resampleandGrouper(freq=...)both do their time binning in theTimeGrouperclass. It readsfreq.rule_codein two places (__init__and_adjust_bin_edges), only to check whether the frequency is anchored to the end of a period, like month end or week.DateOffset(months=1)adds one month but has norule_code, so whenTimeGrouperreads it, it raisesPrefix not defined, and bothresampleandGrouperfail.Fix:
_rule_code(freq), that returns""when the frequency has norule_code, following the existing handling inDatetimeIndexOpsMixin._parse_with_reso."", both checks inTimeGroupergo to theirelsebranch:__init__:closedandlabeldefault to"left", the same as for ordinary frequencies like"D"._adjust_bin_edges: the bin edges are used as they are, without the end-of-period adjustment.Behavior change:
Only calls that raised
NotImplementedError: Prefix not definedbefore are affected.A generic
DateOffsethas no anchor, so the bins start at the date of the first timestamp, the same datesdate_rangegives. For example, data starting on 2024-01-15 gives bins on 01-15, 02-15, 03-15.Easter()had the same error and now works too.Not fixed here: a sub-daily
DateOffsetsuch asDateOffset(hours=12)on intraday data now raisesValueError: Values falls after last bin, the same root cause as BUG: resample by BusinessHour raises ValueError #12351 (being fixed forBusinessHourin BUG: resample with BusinessHour raises or mislabels bins (GH#12351) #71886).closes
DataFrame.resample()breaks when rule parameter is of typeDateOffset#31697Tests added and passed if fixing a bug or adding a new feature
All code checks passed.
Added type annotations to new arguments/methods/functions.
Added an entry in the latest
doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.I have reviewed and followed all the contribution guidelines
Check exactly one of the following, per the automated contributions policy:
I did not use AI to develop this pull request.
I used AI to develop this pull request. I prompted it to follow
AGENTS.md, I have reviewed and understood every change, and I have described above how I used it and exactly which tool, model version, and effort setting — e.g.claude opus 4.8 (xhigh), not justclaude.AI use: I worked with Claude Code (
claude opus 5.5 (high)). Together we identified the root cause, wrote the fix and tests, and ran the new tests. It also helped turn my drafts and thoughts into this description. I also usedgemini argon (high)for an additional review and audit.