Skip to content
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

Mark methods raising AbstractMethodError as abstractmethods? #48909

Open
twoertwein opened this issue Oct 1, 2022 · 4 comments
Open

Mark methods raising AbstractMethodError as abstractmethods? #48909

twoertwein opened this issue Oct 1, 2022 · 4 comments
Labels
Error Reporting Incorrect or improved errors from pandas Refactor Internal refactoring of code

Comments

@twoertwein
Copy link
Member

Many methods raise AbstractMethodError instead of being an abstractmethod. Based on #20363 and #19268 it seems that there might be a performance issue with inheriting from abc.ABC:

This class does not inherit from 'abc.ABCMeta' for performance reasons.

I didn't find a reference of why inheriting from abc.ABC is slow. Is that a python 2 thing? Would it make sense to use abc.ABC+abstractmethod instead of raising AbstractMethodError?

@mroeschke
Copy link
Member

+1 for this change.

I think the docstring for AbstractMethodError included a note for Python 2/3 compat

Raise this error instead of NotImplementedError for abstract methods while keeping compatibility with Python 2 and Python 3.

https://github.com/pandas-dev/pandas/pull/47885/files#diff-bc1b537aba1f5ee1b3e8b9ba7fa82f914561654dbc21038055ee940b039cd47e

@mroeschke mroeschke added Refactor Internal refactoring of code Error Reporting Incorrect or improved errors from pandas labels Oct 1, 2022
@jbrockmendel
Copy link
Member

Very vague recollection of mixing in ABC hurting performance in something. Need to make sure this memory is incorrect.

@TomAugspurger
Copy link
Contributor

@twoertwein the performance issues were specifically around isinstance checks, which still seems to be a thing in Python 3.10:

In [1]: import abc

In [2]: class Regular:
   ...:     pass
   ...:

In [3]: class ABC(abc.ABC):
   ...:     pass
   ...:

In [4]: %timeit isinstance(0, Regular)
59 ns ± 3.65 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

In [5]: %timeit isinstance(0, ABC)
231 ns ± 38.8 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)

@twoertwein
Copy link
Member Author

Thank you @TomAugspurger ! I ran ASV locally some time ago for #48913 but was not "greeted" with a "significant change message".

If there are some classes that are often used in isinstance checks, we could use NotImplementedError instead of using pandas's AbstractMethodError.

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 Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants