Skip to content

Commit

Permalink
[MRG] More informative error message in OneHotEncoder(categories=None…
Browse files Browse the repository at this point in the history
…) with negative integer values (#12180)

* Fix Issue #12179

OneHotEncoder "only non-negative integers" message should suggest using
categories='auto'

* Fix Issue #12179

    OneHotEncoder "only non-negative integers" message should suggest using
    categories='auto'

* Fix Issue #12179

OneHotEncoder "only non-negative integers" message should suggest using
categories='auto'

* Fixes #12180 Modify the error message

* Fix the spacing
  • Loading branch information
ygivenx authored and jnothman committed Oct 15, 2018
1 parent 9136311 commit 9a00af0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sklearn/preprocessing/_encoders.py
Expand Up @@ -421,7 +421,11 @@ def _legacy_fit_transform(self, X):
dtype = getattr(X, 'dtype', None)
X = check_array(X, dtype=np.int)
if np.any(X < 0):
raise ValueError("X needs to contain only non-negative integers.")
raise ValueError("OneHotEncoder in legacy mode cannot handle "
"categories encoded as negative integers. "
"Please set categories='auto' explicitly to "
"be able to use arbitrary integer values as "
"category identifiers.")
n_samples, n_features = X.shape
if (isinstance(self.n_values, six.string_types) and
self.n_values == 'auto'):
Expand Down Expand Up @@ -504,7 +508,11 @@ def _legacy_transform(self, X):
"""Assumes X contains only categorical features."""
X = check_array(X, dtype=np.int)
if np.any(X < 0):
raise ValueError("X needs to contain only non-negative integers.")
raise ValueError("OneHotEncoder in legacy mode cannot handle "
"categories encoded as negative integers. "
"Please set categories='auto' explicitly to "
"be able to use arbitrary integer values as "
"category identifiers.")
n_samples, n_features = X.shape

indices = self._feature_indices_
Expand Down

0 comments on commit 9a00af0

Please sign in to comment.