@@ -164,7 +164,7 @@ def _sparse_matrix_constructor(string_format):
164
164
165
165
166
166
def _ensure_sparse_format (spmatrix , allowed_sparse , dtype , order , copy ,
167
- force_all_finite , convert_sparse_to ):
167
+ force_all_finite ):
168
168
"""Convert a sparse matrix to a given format.
169
169
170
170
Checks the sparse format of spmatrix and converts if necessary.
@@ -178,7 +178,7 @@ def _ensure_sparse_format(spmatrix, allowed_sparse, dtype, order, copy,
178
178
String[s] representing allowed sparse matrix formats ('csc',
179
179
'csr', 'coo', 'dok', 'bsr', 'lil', 'dia'). None means that sparse
180
180
matrix input will raise an error. If the input is sparse but not in
181
- the allowed format, it will be converted to convert_sparse_to .
181
+ the allowed format, it will be converted to the first listed format .
182
182
183
183
order : 'F', 'C' or None (default)
184
184
Whether an array will be forced to be fortran or c-style.
@@ -190,22 +190,15 @@ def _ensure_sparse_format(spmatrix, allowed_sparse, dtype, order, copy,
190
190
force_all_finite : boolean, default=True
191
191
Whether to raise an error on np.inf and np.nan in X.
192
192
193
- convert_sparse_to : string or None (default).
194
- Sparse format to convert sparse matrices to if allowed_sparse is not
195
- None. By default, the first entry of allowed_sparse will be used.
196
-
197
193
Returns
198
194
-------
199
195
spmatrix_convertd : scipy sparse matrix.
200
- Matrix that is ensured to have an allowed type (or convert_sparse_to) .
196
+ Matrix that is ensured to have an allowed type.
201
197
"""
202
198
if allowed_sparse is None :
203
199
raise TypeError ('A sparse matrix was passed, but dense '
204
200
'data is required. Use X.toarray() to '
205
201
'convert to a dense numpy array.' )
206
- if convert_sparse_to not in allowed_sparse :
207
- raise ValueError ("Conversion targed %s not in allowed_sparse: %s"
208
- % (convert_sparse_to , allowed_sparse ))
209
202
sparse_type = spmatrix .format
210
203
if sparse_type in allowed_sparse :
211
204
# correct type
@@ -218,7 +211,7 @@ def _ensure_sparse_format(spmatrix, allowed_sparse, dtype, order, copy,
218
211
spmatrix = spmatrix .astype (dtype )
219
212
else :
220
213
# create new
221
- spmatrix = _sparse_matrix_constructor (convert_sparse_to )(
214
+ spmatrix = _sparse_matrix_constructor (allowed_sparse [ 0 ] )(
222
215
spmatrix , copy = copy , dtype = dtype )
223
216
if force_all_finite :
224
217
if not hasattr (spmatrix , "data" ):
@@ -232,8 +225,7 @@ def _ensure_sparse_format(spmatrix, allowed_sparse, dtype, order, copy,
232
225
233
226
234
227
def check_array (array , allowed_sparse = None , dtype = None , order = None , copy = False ,
235
- force_all_finite = True , convert_sparse_to = None , ensure_2d = True ,
236
- allow_nd = False ):
228
+ force_all_finite = True , ensure_2d = True , allow_nd = False ):
237
229
"""Input validation on an array, list, sparse matrix or similar.
238
230
239
231
By default, the input is converted to an at least 2nd numpy array.
@@ -247,7 +239,7 @@ def check_array(array, allowed_sparse=None, dtype=None, order=None, copy=False,
247
239
String[s] representing allowed sparse matrix formats, such as 'csc',
248
240
'csr', etc. None means that sparse matrix input will raise an error.
249
241
If the input is sparse but not in the allowed format, it will be
250
- converted to convert_sparse_to .
242
+ converted to the first listed format .
251
243
252
244
order : 'F', 'C' or None (default)
253
245
Whether an array will be forced to be fortran or c-style.
@@ -259,10 +251,6 @@ def check_array(array, allowed_sparse=None, dtype=None, order=None, copy=False,
259
251
force_all_finite : boolean, default=True
260
252
Whether to raise an error on np.inf and np.nan in X.
261
253
262
- convert_sparse_to : string or None (default).
263
- Sparse format to convert sparse matrices to if allowed_sparse is not
264
- None. By default, the first entry of allowed_sparse will be used.
265
-
266
254
ensure_2d : boolean, default=True
267
255
Whether to make X at least 2d.
268
256
@@ -276,14 +264,10 @@ def check_array(array, allowed_sparse=None, dtype=None, order=None, copy=False,
276
264
"""
277
265
if isinstance (allowed_sparse , str ):
278
266
allowed_sparse = [allowed_sparse ]
279
- if allowed_sparse is not None and convert_sparse_to is None :
280
- # sensible default converter ;)
281
- convert_sparse_to = allowed_sparse [0 ]
282
267
283
268
if sp .issparse (array ):
284
269
array = _ensure_sparse_format (array , allowed_sparse , dtype , order ,
285
- copy , force_all_finite ,
286
- convert_sparse_to )
270
+ copy , force_all_finite )
287
271
else :
288
272
if ensure_2d :
289
273
array = np .atleast_2d (array )
0 commit comments