pure-predict
pure-predict copied to clipboard
Sklearn object having a preprocessor function cannot be converted
pure_sklearn.map.convert_estimator
function crashes during a conversion of a sklearn unit having a functional variable (a CountVectorizer with a preprocessor parameter in my case).
ValueError: Object contains invalid type: <class 'function'>
To Reproduce
from pure_sklearn.map import convert_estimator
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer(preprocessor=lambda x:x)
vectorizer.fit(["aaaa", "bbbb", "cccc"])
convert_estimator(vectorizer)
Additional context
The bug can be fixed by adding built-in types.FunctionType
into TYPES
tuple of pure_sklearn.utils.py
module. So I suggest to replace:
TYPES = (int, float, str, bool, type)
with:
from types import FunctionType
TYPES = (int, float, str, bool, type, FunctionType)
Hi thanks for raising the issue. Would you be open to submitting a PR with the suggested changes including a unit test to ensure that this error doesn't persist? I'd gladly approve the PR if it is indeed a basic update as you suggest.