@@ -216,6 +216,8 @@ def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False,
216
216
"""Input validation on an array, list, sparse matrix or similar.
217
217
218
218
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.
219
221
220
222
Parameters
221
223
----------
@@ -229,7 +231,8 @@ def check_array(array, accept_sparse=None, dtype=None, order=None, copy=False,
229
231
converted to the first listed format.
230
232
231
233
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.
233
236
234
237
order : 'F', 'C' or None (default=None)
235
238
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,
261
264
else :
262
265
if ensure_2d :
263
266
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
264
270
array = np .array (array , dtype = dtype , order = order , copy = copy )
265
271
if not allow_nd and array .ndim >= 3 :
266
272
raise ValueError ("Found array with dim %d. Expected <= 2" %
0 commit comments