4
4
# Andreas Mueller <amueller@ais.uni-bonn.de>
5
5
# License: BSD 3 clause
6
6
7
- import warnings
8
-
9
7
import numpy as np
10
8
11
9
from ..base import BaseEstimator , TransformerMixin
27
25
'LabelEncoder' ,
28
26
]
29
27
30
- def _warn_numpy_unicode_bug (labels ):
28
+ def _check_numpy_unicode_bug (labels ):
31
29
"""Check that user is not subject to an old numpy bug
32
30
33
31
Fixed in master before 1.7.0:
@@ -37,9 +35,9 @@ def _warn_numpy_unicode_bug(labels):
37
35
and then backported to 1.6.1.
38
36
"""
39
37
if np_version [:3 ] < (1 , 6 , 1 ) and labels .dtype .kind == 'U' :
40
- warnings . warn ("NumPy < 1.6.1 does not implement searchsorted"
41
- " on unicode data correctly. Please upgrade"
42
- " NumPy to use LabelEncoder with unicode inputs." )
38
+ raise RuntimeError ("NumPy < 1.6.1 does not implement searchsorted"
39
+ " on unicode data correctly. Please upgrade"
40
+ " NumPy to use LabelEncoder with unicode inputs." )
43
41
44
42
45
43
class LabelEncoder (BaseEstimator , TransformerMixin ):
@@ -97,7 +95,7 @@ def fit(self, y):
97
95
self : returns an instance of self.
98
96
"""
99
97
y = column_or_1d (y , warn = True )
100
- _warn_numpy_unicode_bug (y )
98
+ _check_numpy_unicode_bug (y )
101
99
self .classes_ = np .unique (y )
102
100
return self
103
101
@@ -114,7 +112,7 @@ def fit_transform(self, y):
114
112
y : array-like of shape [n_samples]
115
113
"""
116
114
y = column_or_1d (y , warn = True )
117
- _warn_numpy_unicode_bug (y )
115
+ _check_numpy_unicode_bug (y )
118
116
self .classes_ , y = unique (y , return_inverse = True )
119
117
return y
120
118
@@ -133,7 +131,7 @@ def transform(self, y):
133
131
self ._check_fitted ()
134
132
135
133
classes = np .unique (y )
136
- _warn_numpy_unicode_bug (classes )
134
+ _check_numpy_unicode_bug (classes )
137
135
if len (np .intersect1d (classes , self .classes_ )) < len (classes ):
138
136
diff = np .setdiff1d (classes , self .classes_ )
139
137
raise ValueError ("y contains new labels: %s" % str (diff ))
0 commit comments