BUG: PeriodIndex.from_fields rejects non-December quarterly freqs (#55784) - #66553
Open
karandhaodiyal28-hash wants to merge 1 commit into
Open
Conversation
| base = libperiod.freq_to_dtype_code(freq) | ||
| if base != FreqGroup.FR_QTR.value: | ||
| if FreqGroup.from_period_dtype_code(base) != FreqGroup.FR_QTR: | ||
| raise AssertionError("base must equal FR_QTR") |
Member
There was a problem hiding this comment.
is this reachable? if so, we should be raising something other than AssertionError
Member
|
I suspect the scalar case is similarly broken if you want to address it in a followup |
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.
doc/source/whatsnew/vX.X.X.rstfile_range_from_fieldsvalidated a quarterlyfreqwith an exact-equality checkbase != FreqGroup.FR_QTR.value. Quarterly period dtype codes areFR_QTRplus the anchor-month offset (
Q-DEC=2000,Q-JAN=2001, ...,Q-FEB=2002), sothe check only accepted
Q-DECand raisedAssertionError: base must equal FR_QTRfor every other quarterly anchor -- even though the equivalent scalarPeriod(year=2014, quarter=3, freq=QuarterEnd(startingMonth=2))works fine.The fix uses a frequency-group membership test instead of exact equality:
baseitself is unchanged (it is still passed tolibperiod.period_ordinal),so the anchored quarterly frequency is preserved; only the guard is corrected to
accept any code in the
FR_QTRgroup. Added a regression test parametrized overall twelve quarterly anchors, asserting the result matches the scalar
Periodpath. Non-quarterly frequencies are still rejected, and the existing
Q-DECbehavior is unchanged.