Skip to content

ENH: raise TypeError if offsets which are not supported as period frequency pass to asfreq  #56718

Closed
@natmokval

Description

@natmokval

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

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

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions