### Pandas version checks - [X] I have checked that this issue has not already been reported. - [X] I have confirmed this bug exists on the [latest version](https://pandas.pydata.org/docs/whatsnew/index.html) of pandas. - [X] I have confirmed this bug exists on the [main branch](https://pandas.pydata.org/docs/dev/getting_started/install.html#installing-the-development-version-of-pandas) of pandas. ### Reproducible Example ```python import pandas as pd index = pd.PeriodIndex(["2020-01-01", "2021-01-01"], freq="M") df = pd.DataFrame({"a": pd.Series([0, 1], index=index)}) print(df.index) expected = df.asfreq(freq="2MS") ``` ### Issue Description In this case we get `AttributeError: 'pandas._libs.tslibs.offsets.MonthBegin' object has no attribute '_period_dtype_code'` ### Expected Behavior the expected message should be `TypeError: MS is not supported as period frequency` ### Installed Versions <details> Replace this line with the output of pd.show_versions() </details>