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
?
Comment From: mroeschke
+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
Comment From: jbrockmendel
Very vague recollection of mixing in ABC hurting performance in something. Need to make sure this memory is incorrect.
Comment From: TomAugspurger
@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)
Comment From: twoertwein
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.