Skip to content

API: IncompatibleFrequency should subclass TypeError #55782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 tasks done
jbrockmendel opened this issue Oct 31, 2023 · 3 comments
Open
3 tasks done

API: IncompatibleFrequency should subclass TypeError #55782

jbrockmendel opened this issue Oct 31, 2023 · 3 comments
Labels
API Design Error Reporting Incorrect or improved errors from pandas

Comments

@jbrockmendel
Copy link
Member

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()

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 31, 2023
@lithomas1 lithomas1 added API Design Error Reporting Incorrect or improved errors from pandas and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 3, 2023
@lithomas1 lithomas1 added this to the 3.0 milestone Nov 3, 2023
@jbrockmendel
Copy link
Member Author

@mroeschke thoughts about doing this as a breaking change?

@mroeschke
Copy link
Member

Sounds minor enough so I'd be OK with it

@jbrockmendel
Copy link
Member Author

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

@mroeschke mroeschke removed this from the 3.0 milestone Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

3 participants