def _sample_rows(self, X, Y, sample_shape, seed):
if sample_shape[<NUM_LIT:0>] is None or X.shape[<NUM_LIT:0>] <= sample_shape[<NUM_LIT:0>]:<EOL><INDENT>X_sample, Y_sample = X, Y<EOL><DEDENT>elif Y is None:<EOL><INDENT>np.random.seed(seed)<EOL>row_indices = np.random.choice(<EOL>X.shape[<NUM_LIT:0>], size=sample_shape[<NUM_LIT:0>], replace=False<EOL>)<EOL>X_sample, Y_sample = X.iloc[row_indices], Y<EOL><DEDENT>else:<EOL><INDENT>drop_size = X.shape[<NUM_LIT:0>] - sample_shape[<NUM_LIT:0>]<EOL>sample_size = sample_shape[<NUM_LIT:0>]<EOL>sss = StratifiedShuffleSplit(<EOL>n_splits=<NUM_LIT:2>, test_size=drop_size, train_size=sample_size, random_state=seed<EOL>)<EOL>row_indices, _ = next(sss.split(X, Y))<EOL>X_sample, Y_sample = X.iloc[row_indices], Y.iloc[row_indices]<EOL><DEDENT>return (X_sample, Y_sample)<EOL>
Stratified uniform sampling of rows, according to the classes in Y.
Ensures there are enough samples from each class in Y for cross
validation.