8000 make check_array convert object to float. · scikit-learn/scikit-learn@2c54c5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c54c5e

Browse files
committed
make check_array convert object to float.
1 parent d5db44f commit 2c54c5e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sklearn/utils/validation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False,
216216
"""Input validation on an array, list, sparse matrix or similar.
217217
218218
By default, the input is converted to an at least 2nd numpy array.
219+
If the dtype of the array is object, we attempt converting to float,
220+
raising on failure.
219221
220222
Parameters
221223
----------
@@ -229,7 +231,8 @@ def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False,
229231
converted to the first listed format.
230232
231233
dtype : string, type or None (default=none)
232-
Data type of result. If None, the dtype of the input is preserved.
234+
Data type of result. If None, the dtype of the input is preserved,
235+
unless array.dtype is object.
233236
234237
order : 'F', 'C' or None (default=None)
235238
Whether an array will be forced to be fortran or c-style.
@@ -261,6 +264,9 @@ def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False,
261264
else:
262265
if ensure_2d:
263266
array = np.atleast_2d(array)
267+
if dtype is None and getattr(array, "dtype", None) is object:
268+
# if no conversion is given, and input is object, convert to float.
269+
dtype = np.float
264270
array = np.array(array, dtype=dtype, order=order, copy=copy)
265271
if not allow_nd and array.ndim >= 3:
266272
raise ValueError("Found array with dim %d. Expected <= 2" %

0 commit comments

Comments
 (0)
0