@@ -165,35 +165,35 @@ def _sparse_matrix_constructor(string_format):
165
165
raise ValueError ("Don't know how to construct a sparse matrix of type %s" % string_format )
166
166
167
167
168
- def _ensure_sparse_format (array , allowed_sparse , convert_sparse_to , dtype ,
168
+ def _ensure_sparse_format (spmatrix , allowed_sparse , convert_sparse_to , dtype ,
169
169
order , copy , force_all_finite ):
170
170
if allowed_sparse is None :
171
171
raise TypeError ('A sparse matrix was passed, but dense '
172
172
'data is required. Use X.toarray() to '
173
173
'convert to a dense numpy array.' )
174
- sparse_type = _get_sparse_type_string (array )
174
+ sparse_type = _get_sparse_type_string (spmatrix )
175
175
if sparse_type in allowed_sparse :
176
176
# correct type
177
- if dtype == array .dtype or dtype is None :
177
+ if dtype == spmatrix .dtype or dtype is None :
178
178
# correct dtype
179
179
if copy :
180
- array = array .copy ()
180
+ spmatrix = spmatrix .copy ()
181
181
else :
182
182
# convert dtype
183
- array = array .astype (dtype )
183
+ spmatrix = spmatrix .astype (dtype )
184
184
else :
185
185
# create new
186
- array = _sparse_matrix_constructor (convert_sparse_to )(array , copy = copy ,
187
- dtype = dtype )
186
+ spmatrix = _sparse_matrix_constructor (convert_sparse_to )(
187
+ spmatrix , copy = copy , dtype = dtype )
188
188
if force_all_finite :
189
- _assert_all_finite (array .data )
190
- array .data = np .array (array .data , copy = False , order = order )
191
- return array
189
+ _assert_all_finite (spmatrix .data )
190
+ spmatrix .data = np .array (spmatrix .data , copy = False , order = order )
191
+ return spmatrix
192
192
193
193
194
194
def check_array (array , allowed_sparse = None , dtype = None , order = None , copy = False ,
195
195
force_all_finite = True , convert_sparse_to = None , make_2d = True ,
196
- allow_nd = False ):
196
+ allow_nd = True ):
197
197
"""Check everything about an array"""
198
198
if isinstance (allowed_sparse , str ):
199
199
allowed_sparse = [allowed_sparse ]
@@ -292,7 +292,11 @@ def check_arrays(*arrays, **options):
292
292
293
293
checked_arrays = []
294
294
for array in arrays :
295
- if (force_arrays or hasattr (array , "__array__" ) or hasattr (array , "shape" )):
295
+ if array is None :
296
+ checked_arrays .append (array )
297
+ continue
298
+
299
+ if force_arrays or sp .issparse (array ):
296
300
array = check_array (array , allow_sparse , dtype , order , copy = copy ,
297
301
make_2d = False , allow_nd = allow_nd ,
298
302
force_all_finite = force_finite )
0 commit comments