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 of pandas.

  • [X] 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()

Comment From: jbrockmendel

@mroeschke thoughts about doing this as a breaking change?

Comment From: mroeschke

Sounds minor enough so I'd be OK with it

Comment From: jbrockmendel

@jorisvandenbossche OK with this? if you object id rather find out now than a few weeks after a PR is merged