Skip to content

Regression: Pipelines don't accept steps as a tuple in 0.19 #9587

Closed
@reiinakano

Description

@reiinakano

Description

TypeError: 'tuple' object does not support item assignment error thrown when calling fit on a Pipeline whose steps parameter was initialized with an n-tuple (as opposed to a list) of (name, transform) tuples.

Previous versions of sklearn Pipelines worked when an n-tuple was used for steps. I guess new functionality associated with Pipelines now requires that steps be mutable.

I guess there are a few choices here:

  1. Automatically handle the case of an n-tuple being passed by creating a new list for self.steps and copying over the tuple's items to it. And maybe throw a warning for behavior's deprecation.
  2. Throw an immediate error during initialization if steps is a tuple. Of course, this is still a breaking change, but at least, the user won't have to wait until calling fit before discovering something is wrong.

I could submit a PR for this if you want.

Steps/Code to Reproduce

from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier
from sklearn.decomposition import PCA
from sklearn.datasets import load_breast_cancer

pipeline = Pipeline((('pca', PCA()), ('rf', RandomForestClassifier())))
X, y = load_breast_cancer(True)
pipeline.fit(X, y)

Expected Results

This had no errors in previous versions

Actual Results

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 257, in fit
    Xt, fit_params = self._fit(X, y, **fit_params)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/pipeline.py", line 226, in _fit
    self.steps[step_idx] = (name, fitted_transformer)
TypeError: 'tuple' object does not support item assignment

Versions

Linux-4.4.0-36-generic-x86_64-with-Ubuntu-14.04-trusty
('Python', '2.7.6 (default, Jun 22 2015, 17:58:13) \n[GCC 4.8.2]')
('NumPy', '1.13.1')
('SciPy', '0.19.0')
('Scikit-Learn', '0.19.0')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions