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

ThirdPartyComponents.add_component check for explicit base class results in redundant inheritance #1604

Open
AmirAlavi opened this issue Nov 6, 2022 · 1 comment
Labels
Milestone

Comments

@AmirAlavi
Copy link

Auto-sklearn is awesome, I'm really enjoying this great library!

Currently, this line here

if inspect.isclass(obj) and self.base_class in obj.__bases__:

explicitly checks the .__bases__ attribute of the 3rd party component you are adding to make sure it inherits directly from e.g. AutoSklearnPreprocessingAlgorithm, rather than checking if it's an instance of it with isinstance(obj, self.base_class).

This results in errors like in #1268 (comment).

This makes it awkward to extend the built in preprocessors. In particular, I'm going to try a handful of different data preprocessor strategies that share a lot of code, so it makes a lot of sense to have some inheritance structure for these. However, only the parent at the base of the hierarchy (e.g. MyAbstractCustomPreprocessingAlorithm) will extend directly from AutoSklearnPreprocessingAlgorithm and contains all the common code. The concrete classes will all extend MyAbstractCustomPreprocessingAlorithm, so AutoSklearnPreprocessingAlgorithm will not be in their .__bases__ attribute, but they do indeed implement the preprocessing interface.

The fix is to subclass AutoSklearnPreprocessingAlgorithm in all of the concrete classes as well, but that shouldn't be necessary and feels kind of weird to do.

Is there a reason why we must check for an explicit base class?

@eddiebergman
Copy link
Contributor

Hi @AmirAlavi,

I have no idea why we have this, my guess it's some relic of Python 2 code but I wouldn't know for sure. I would rather do as you say and do isinstance(obj, cls), thanks for pointing it out.

Best,
Eddie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants