ENH: Raise TypeError when converting DatetimeIndex to PeriodIndex with invalid period frequency by natmokval · Pull Request #56243 · pandas-dev/pandas (original) (raw)

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'