Skip to content

Conversation

Maaz-319
Copy link
Contributor

Fixing an error message in the AbstractMethodError class found in pandas/errors/init.py.
Currently:
raise ValueError(
f"methodtype must be one of {methodtype}, got {types} instead."
)
Here, {methodtype} and {types} are swapped.
This means if you called this error with methodtype="foo", the message would read:
methodtype must be one of foo, got {'method', 'classmethod', 'staticmethod', 'property'} instead.

That’s confusing, because the set of valid types should be listed after “must be one of”, and the invalid value you passed should be listed after “got”.

Corrected:

raise ValueError(
f"methodtype must be one of {types}, got {methodtype} instead."
)
Now, if you called this error with methodtype="foo", the message would read:
methodtype must be one of {'method', 'classmethod', 'staticmethod', 'property'}, got foo instead.

This is clearer and follows standard error message conventions.

@Maaz-319
Copy link
Contributor Author

pre-commit.ci autofix

@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Jul 11, 2025
@mroeschke mroeschke added this to the 3.0 milestone Jul 11, 2025
@mroeschke mroeschke merged commit e83b820 into pandas-dev:main Jul 11, 2025
47 checks passed
@mroeschke
Copy link
Member

Thanks @Maaz-319

@Maaz-319
Copy link
Contributor Author

Thanks @Maaz-319

Glad to contribute @mroeschke

eicchen pushed a commit to eicchen/pandas that referenced this pull request Aug 19, 2025
…ment (pandas-dev#61827)

* DOC: Correct error message in AbstractMethodError for methodtype argument

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Error Reporting Incorrect or improved errors from pandas

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants