Skip to content

force pipeline steps to be list not a tuple #9221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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: 3 additions & 0 deletions sklearn/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def set_params(self, **kwargs):
return self

def _validate_steps(self):
if isinstance(self.steps, tuple):
self.steps = list(self.steps)
Copy link
Member

Choose a reason for hiding this comment

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

Modifying an init argument :(

Copy link
Member Author

@agramfort agramfort Jun 25, 2017

Choose a reason for hiding this comment

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

what do you suggest?

it is modified anyway in : L226

self.steps[step_idx] = (name, fitted_transformer)

which is what created the problem


names, estimators = zip(*self.steps)

# validate names
Expand Down
2 changes: 1 addition & 1 deletion sklearn/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_pipeline_methods_anova():
# Test with Anova + LogisticRegression
clf = LogisticRegression()
filter1 = SelectKBest(f_classif, k=2)
pipe = Pipeline([('anova', filter1), ('logistic', clf)])
pipe = Pipeline((('anova', filter1), ('logistic', clf)))
pipe.fit(X, y)
pipe.predict(X)
pipe.predict_proba(X)
Expand Down
13 changes: 12 additions & 1 deletion sklearn/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,18 @@ def _get_n_jobs(n_jobs):


def tosequence(x):
"""Cast iterable x to a Sequence, avoiding a copy if possible."""
"""Cast iterable x to a Sequence, avoiding a copy if possible.

Parameters
----------
x : iterable
The input to make a sequence from

Return
------
x_seq : iterable
The sequence.
"""
if isinstance(x, np.ndarray):
return np.asarray(x)
elif isinstance(x, Sequence):
Expand Down