diff --git a/sklearn/tests/test_docstrings.py b/sklearn/tests/test_docstrings.py index 591107502c296..00206cfb86c9b 100644 --- a/sklearn/tests/test_docstrings.py +++ b/sklearn/tests/test_docstrings.py @@ -16,7 +16,6 @@ "sklearn.utils.extmath.randomized_svd", "sklearn.utils.extmath.svd_flip", "sklearn.utils.gen_batches", - "sklearn.utils.gen_even_slices", "sklearn.utils.metaestimators.if_delegate_has_method", ] FUNCTION_DOCSTRING_IGNORE_LIST = set(FUNCTION_DOCSTRING_IGNORE_LIST) diff --git a/sklearn/utils/__init__.py b/sklearn/utils/__init__.py index 6f3c148a19025..da1f9c38bca47 100644 --- a/sklearn/utils/__init__.py +++ b/sklearn/utils/__init__.py @@ -746,21 +746,25 @@ def gen_batches(n, batch_size, *, min_batch_size=0): def gen_even_slices(n, n_packs, *, n_samples=None): - """Generator to create n_packs slices going up to n. + """Generator to create `n_packs` evenly spaced slices going up to `n`. + + If `n_packs` does not divide `n`, except for the first `n % n_packs` + slices, remaining slices may contain fewer elements. Parameters ---------- n : int + Size of the sequence. n_packs : int Number of slices to generate. n_samples : int, default=None - Number of samples. Pass n_samples when the slices are to be used for + Number of samples. Pass `n_samples` when the slices are to be used for sparse matrix indexing; slicing off-the-end raises an exception, while it works for NumPy arrays. Yields ------ - slice + `slice` representing a set of indices from 0 to n. See Also --------