Skip to content

Commit 89b5b8e

Browse files
authored
Allow to pass callables as outer CV (#90)
Passing an unsized iterable (such as a generator) as an outer CV does not work if the experiment has several datasets/estimators. as in that case the iterable is exhausted in the first iteration, raising `StopIteration` for the following datasets/estimators. We can instead allow to pass a callable that returns a fresh instance of the iterable for each combination. Note: the type hints and documentation have not been updated for now.
1 parent 148ee53 commit 89b5b8e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

skdatasets/utils/experiment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def get_n_splits(
100100
CVLike = Union[
101101
CVSplitter,
102102
Iterable[IndicesType],
103+
Callable[[], Iterable[IndicesType]],
103104
int,
104105
None,
105106
]
@@ -176,6 +177,9 @@ def _iterate_outer_cv(
176177
y: TargetType,
177178
) -> Iterable[Tuple[DataType, TargetType, DataType, TargetType]]:
178179
"""Iterate over multiple partitions."""
180+
if callable(outer_cv):
181+
outer_cv = outer_cv()
182+
179183
if isinstance(outer_cv, Iterable):
180184
outer_cv, cv_copy = itertools.tee(outer_cv)
181185
if len(next(cv_copy)) == 4:

0 commit comments

Comments
 (0)