Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sklearn/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ def set_params(self, **kwargs):
return self

def _validate_steps(self):
if not self.steps:
raise ValueError("The pipeline is empty. Please add steps.")
names, estimators = zip(*self.steps)

# validate names
Expand Down Expand Up @@ -1289,7 +1291,6 @@ def __sklearn_is_fitted__(self):

An empty pipeline is considered fitted.
"""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is where I wanted to to check if the pipeline had steps. But this means the display will fail as well.
And I just saw this: "An empty pipeline is considered fitted." This means that the HTML display is actually correct.

# First find the last step that is not 'passthrough'
last_step = None
for _, estimator in reversed(self.steps):
Expand Down
10 changes: 10 additions & 0 deletions sklearn/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ def test_pipeline_invalid_parameters():
assert params == params2


def test_empty_pipeline():
X = iris.data
y = iris.target

pipe = Pipeline([])
msg = "The pipeline is empty. Please add steps."
with pytest.raises(ValueError, match=msg):
pipe.fit(X, y)


def test_pipeline_init_tuple():
# Pipeline accepts steps as tuple
X = np.array([[1, 2]])
Expand Down