@@ -169,7 +169,9 @@ def resample(*arrays, **options):
169169
170170 Parameters
171171 ----------
172- *arrays : sequence of arrays or scipy.sparse matrices with same shape[0]
172+ *arrays : sequence of indexable data-structures
173+ Indexable data-structures can be arrays, lists, dataframes or scipy
174+ sparse matrices with consistent first dimension.
173175
174176 replace : boolean, True by default
175177 Implements resampling with replacement. If False, this will implement
@@ -184,16 +186,15 @@ def resample(*arrays, **options):
184186
185187 Returns
186188 -------
187- resampled_arrays : sequence of arrays or scipy.sparse matrices with same \
188- shape[0]
189+ resampled_arrays : sequence of indexable data-structures
189190 Sequence of resampled views of the collections. The original arrays are
190191 not impacted.
191192
192193 Examples
193194 --------
194195 It is possible to mix sparse and dense arrays in the same run::
195196
196- >>> X = [[1., 0.], [2., 1.], [0., 0.]]
197+ >>> X = np.array( [[1., 0.], [2., 1.], [0., 0.]])
197198 >>> y = np.array([0, 1, 2])
198199
199200 >>> from scipy.sparse import coo_matrix
@@ -246,8 +247,6 @@ def resample(*arrays, **options):
246247 max_n_samples , n_samples ))
247248
248249 check_consistent_length (* arrays )
249- arrays = [check_array (x , accept_sparse = 'csr' , ensure_2d = False ,
250- allow_nd = True ) for x in arrays ]
251250
252251 if replace :
253252 indices = random_state .randint (0 , n_samples , size = (max_n_samples ,))
@@ -256,12 +255,9 @@ def resample(*arrays, **options):
256255 random_state .shuffle (indices )
257256 indices = indices [:max_n_samples ]
258257
259- resampled_arrays = []
260-
261- for array in arrays :
262- array = array [indices ]
263- resampled_arrays .append (array )
264-
258+ # convert sparse matrices to CSR for row-based indexing
259+ arrays = [a .tocsr () if issparse (a ) else a for a in arrays ]
260+ resampled_arrays = [safe_indexing (a , indices ) for a in arrays ]
265261 if len (resampled_arrays ) == 1 :
266262 # syntactic sugar for the unit argument case
267263 return resampled_arrays [0 ]
@@ -277,7 +273,9 @@ def shuffle(*arrays, **options):
277273
278274 Parameters
279275 ----------
280- *arrays : sequence of arrays or scipy.sparse matrices with same shape[0]
276+ *arrays : sequence of indexable data-structures
277+ Indexable data-structures can be arrays, lists, dataframes or scipy
278+ sparse matrices with consistent first dimension.
281279
282280 random_state : int or RandomState instance
283281 Control the shuffling for reproducible behavior.
@@ -288,16 +286,15 @@ def shuffle(*arrays, **options):
288286
289287 Returns
290288 -------
291- shuffled_arrays : sequence of arrays or scipy.sparse matrices with same \
292- shape[0]
289+ shuffled_arrays : sequence of indexable data-structures
293290 Sequence of shuffled views of the collections. The original arrays are
294291 not impacted.
295292
296293 Examples
297294 --------
298295 It is possible to mix sparse and dense arrays in the same run::
299296
300- >>> X = [[1., 0.], [2., 1.], [0., 0.]]
297+ >>> X = np.array( [[1., 0.], [2., 1.], [0., 0.]])
301298 >>> y = np.array([0, 1, 2])
302299
303300 >>> from scipy.sparse import coo_matrix
0 commit comments