Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Sklearn object having a preprocessor function cannot be converted #15

Open
ogunoz opened this issue Apr 1, 2021 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@ogunoz
Copy link

ogunoz commented Apr 1, 2021

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 ogunoz added the bug Something isn't working label Apr 1, 2021
@denver1117
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants