Skip to content

ENH: Raise TypeError when converting DatetimeIndex to PeriodIndex with invalid period frequency #56243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

natmokval
Copy link
Contributor

xref #55844

Added to dt64arr_to_periodarr check if frequency is supported as period frequency, if not a TypeError is raised.

The reason: so far in the example below

>>> ts = pd.date_range('1/1/2012', periods=4, freq="BMS")
>>> ts.to_period()

we get
AttributeError: 'pandas._libs.tslibs.offsets.BusinessMonthBegin' object has no attribute '_period_dtype_code'

@natmokval natmokval marked this pull request as ready for review November 30, 2023 09:47
@natmokval natmokval added the Frequency DateOffsets label Nov 30, 2023
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always good to have better error messages, thanks @natmokval !

@MarcoGorelli MarcoGorelli merged commit df913e7 into pandas-dev:main Dec 4, 2023
@MarcoGorelli MarcoGorelli added this to the 2.2 milestone Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants