Skip to content

Commit f5fcca0

Browse files
committed
add catch for empty resampling
1 parent 7bba999 commit f5fcca0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/resampling.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const AbstractRow = Union{AbstractVector{<:Integer}, Colon}
44
const TrainTestPair = Tuple{AbstractRow, AbstractRow}
55
const TrainTestPairs = Union{
6-
NTuple{<:Any,TrainTestPair},
6+
Tuple{Vararg{TrainTestPair}},
77
AbstractVector{<:TrainTestPair},
88
}
99

@@ -102,6 +102,12 @@ const ERR_BAD_RESAMPLING_OPTION = ArgumentError(
102102
"of the form `(train_rows, test_rows)`"
103103
)
104104

105+
const ERR_EMPTY_RESAMPLING_OPTION = ArgumentError(
106+
"`resampling` cannot be emtpy. It must be an "*
107+
"`MLJ.ResamplingStrategy` or a vector (or tuple) of tuples "*
108+
"of the form `(train_rows, test_rows)`"
109+
)
110+
105111

106112
# ==================================================================
107113
## RESAMPLING STRATEGIES
@@ -1440,6 +1446,7 @@ function evaluate!(
14401446
# Note: `rows` and `repeats` are only passed to the final `PeformanceEvaluation`
14411447
# object to be returned and are not otherwise used here.
14421448

1449+
isempty(resampling) && throw(ERR_EMPTY_RESAMPLING_OPTION)
14431450
resampling isa TrainTestPairs || throw(ERR_BAD_RESAMPLING_OPTION)
14441451

14451452
X = mach.args[1]()

test/resampling.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,15 @@ end
276276
model = DeterministicConstantRegressor()
277277
mach = machine(model, X, y, cache=cache)
278278

279-
# check catch for bad `resampling` option:
279+
# check catch for bad `resampling` options:
280280
@test_throws(
281281
MLJBase.ERR_BAD_RESAMPLING_OPTION,
282282
evaluate(model, X, y; resampling="junk", verbosity=0, acceleration=accel),
283283
)
284+
@test_throws(
285+
MLJBase.ERR_EMPTY_RESAMPLING_OPTION,
286+
evaluate(model, X, y; resampling=[], verbosity=0, acceleration=accel),
287+
)
284288

285289
# check we can provide tuples of pairs, instead of vectors of pairs, in
286290
# `resampling` option:

0 commit comments

Comments
 (0)