pure-predict icon indicating copy to clipboard operation
pure-predict copied to clipboard

Sklearn object having a preprocessor function cannot be converted

Open ogunoz opened this issue 3 years ago • 1 comments

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)

ogunoz avatar Apr 01 '21 23:04 ogunoz

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.

denver1117 avatar Jun 20 '21 15:06 denver1117