Skip to content

API: IncompatibleFrequency should subclass TypeError #55782

Open
@jbrockmendel

Description

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

per1 = pd.Period("2016Q1", freq="Q")
per2 = per1.asfreq("M")

>>> per1 < per2
pandas._libs.tslibs.period.IncompatibleFrequency: Input has different freq=M from Period(freq=Q-DEC)

idx = pd.Index([per1, per2])
idx2 = pd.Index([per1, "foo"])

>>> idx.is_monotonic_increasing
pandas._libs.tslibs.period.IncompatibleFrequency: Input has different freq=Q-DEC from Period(freq=M)

>>> idx2.is_monotonic_increasing
False

Issue Description

In general the exception you get from mismatched comparisons should be a TypeError (xref #54847). ATM IncompatibleFrequency subclasses ValueError. Might be worth changing that in 3.0.

Expected Behavior

NA

Installed Versions

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions