File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -320,6 +320,8 @@ def set_params(self, **kwargs):
320
320
return self
321
321
322
322
def _validate_steps (self ):
323
+ if not self .steps :
324
+ raise ValueError ("The pipeline is empty. Please add steps." )
323
325
names , estimators = zip (* self .steps )
324
326
325
327
# validate names
@@ -1289,7 +1291,6 @@ def __sklearn_is_fitted__(self):
1289
1291
1290
1292
An empty pipeline is considered fitted.
1291
1293
"""
1292
-
1293
1294
# First find the last step that is not 'passthrough'
1294
1295
last_step = None
1295
1296
for _ , estimator in reversed (self .steps ):
Original file line number Diff line number Diff line change @@ -282,6 +282,16 @@ def test_pipeline_invalid_parameters():
282
282
assert params == params2
283
283
284
284
285
+ def test_empty_pipeline ():
286
+ X = iris .data
287
+ y = iris .target
288
+
289
+ pipe = Pipeline ([])
290
+ msg = "The pipeline is empty. Please add steps."
291
+ with pytest .raises (ValueError , match = msg ):
292
+ pipe .fit (X , y )
293
+
294
+
285
295
def test_pipeline_init_tuple ():
286
296
# Pipeline accepts steps as tuple
287
297
X = np .array ([[1 , 2 ]])
You can’t perform that action at this time.
0 commit comments