alegonz / baikal

A graph-based functional API for building complex scikit-learn pipelines.
https://baikal.readthedocs.io
BSD 3-Clause "New" or "Revised" License
592 stars 30 forks source link

RuntimeError when printing step made from BaseEstimator subclass #31

Closed jrderuiter closed 4 years ago

jrderuiter commented 4 years ago

What is the bug?

When printing a representation of a step made from a BaseEstimator subclass (see below), I get the following runtime error:

RuntimeError: scikit-learn estimators should always specify their parameters in the signature of their __init__ (no varargs). <super: <class '_StepBase'>, <SklearnTransformer object>> with constructor (*args, **kwargs) doesn't  follow this convention.

How to reproduce it?

from baikal import make_step
from sklearn.base import TransformerMixin, BaseEstimator

class MyTransformer(TransformerMixin, BaseEstimator):
    pass

MyTransformerStep = make_step(MyTransformer)
MyTransformerStep()

What behavior did you expect?

To not get a runtime error.

What versions are you using?

Any additional information? Add here any other information about the problem that could be relevant.

alegonz commented 4 years ago

Thank you for the bug report!

I could reproduce it here, too. It fails when the class you're making a step from lacks an __init__ method and resolves to a delegate of object.__init__ which has a (*args, **kwargs) signature which is incompatible with scikit-learn. I'll work on a fix which I plan to release as version 0.3.1. In the meantime, to make it work please define an __init__ method in your base class, if possible.

alegonz commented 4 years ago

@jrderuiter Just released v0.3.1 with that bug fixed.

jrderuiter commented 4 years ago

Great, thanks!