Elffuss BraidHub

kikocis/auto-code-rover public

main · 1.6 KiBRawPermalink
1LabelEncoder transform fails for empty lists (for certain inputs)
2Python 3.6.3, scikit_learn 0.19.1
3
4Depending on which datatypes were used to fit the LabelEncoder, transforming empty lists works or not. Expected behavior would be that empty arrays are returned in both cases.
5
6```python
7>>> from sklearn.preprocessing import LabelEncoder
8>>> le = LabelEncoder()
9>>> le.fit([1,2])
10LabelEncoder()
11>>> le.transform([])
12array([], dtype=int64)
13>>> le.fit(["a","b"])
14LabelEncoder()
15>>> le.transform([])
16Traceback (most recent call last):
17 File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 57, in _wrapfunc
18 return getattr(obj, method)(*args, **kwds)
19TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'
20
21During handling of the above exception, another exception occurred:
22
23Traceback (most recent call last):
24 File "<stdin>", line 1, in <module>
25 File "[...]\Python36\lib\site-packages\sklearn\preprocessing\label.py", line 134, in transform
26 return np.searchsorted(self.classes_, y)
27 File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 1075, in searchsorted
28 return _wrapfunc(a, 'searchsorted', v, side=side, sorter=sorter)
29 File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 67, in _wrapfunc
30 return _wrapit(obj, method, *args, **kwds)
31 File "[...]\Python36\lib\site-packages\numpy\core\fromnumeric.py", line 47, in _wrapit
32 result = getattr(asarray(obj), method)(*args, **kwds)
33TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'
34```