Skip to content

Commit

Permalink
[MRG] MAINT Adds tag categorical to OneHotEncoder (#14068)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjpfan authored and jnothman committed Jun 24, 2019
1 parent f41cd1e commit 0bdd920
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sklearn/preprocessing/_encoders.py
Expand Up @@ -144,6 +144,9 @@ def _transform(self, X, handle_unknown='error'):

return X_int, X_mask

def _more_tags(self):
return {'X_types': ['categorical']}


class OneHotEncoder(_BaseEncoder):
"""Encode categorical integer features as a one-hot numeric array.
Expand Down Expand Up @@ -656,6 +659,3 @@ def inverse_transform(self, X):
X_tr[:, i] = self.categories_[i][labels]

return X_tr

def _more_tags(self):
return {'X_types': ['categorical']}
5 changes: 5 additions & 0 deletions sklearn/preprocessing/tests/test_encoders.py
Expand Up @@ -671,3 +671,8 @@ def test_categories(density, drop):
assert cat_list[drop_idx] == drop_cat
assert isinstance(ohe_test.drop_idx_, np.ndarray)
assert ohe_test.drop_idx_.dtype == np.int_


@pytest.mark.parametrize('Encoder', [OneHotEncoder, OrdinalEncoder])
def test_encoders_has_categorical_tags(Encoder):
assert 'categorical' in Encoder()._get_tags()['X_types']

0 comments on commit 0bdd920

Please sign in to comment.