Skip to content

Param validation for Dictvectorizer #23820

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

Merged
merged 4 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sklearn/feature_extraction/_dict_vectorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class DictVectorizer(TransformerMixin, BaseEstimator):
array([[0., 0., 4.]])
"""

_parameter_constraints = {
"dtype": "no_validation", # validation delegated to numpy,
"separator": [str],
"sparse": ["boolean"],
"sort": ["boolean"],
}

def __init__(self, *, dtype=np.float64, separator="=", sparse=True, sort=True):
self.dtype = dtype
self.separator = separator
Expand Down Expand Up @@ -154,6 +161,7 @@ def fit(self, X, y=None):
self : object
DictVectorizer class instance.
"""
self._validate_params()
feature_names = []
vocab = {}

Expand Down Expand Up @@ -310,6 +318,7 @@ def fit_transform(self, X, y=None):
Xa : {array, sparse matrix}
Feature vectors; always 2-d.
"""
self._validate_params()
return self._transform(X, fitting=True)

def inverse_transform(self, X, dict_type=dict):
Expand Down
1 change: 0 additions & 1 deletion sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ def test_estimators_do_not_raise_errors_in_init_or_set_params(Estimator):
"CalibratedClassifierCV",
"ClassifierChain",
"CountVectorizer",
"DictVectorizer",
"DictionaryLearning",
"ElasticNetCV",
"EllipticEnvelope",
Expand Down