Skip to content

Pipeline should implement __len__ #13418

@kszucs

Description

@kszucs

Description

With the new indexing support pipe[:len(pipe)] raises an error.

Steps/Code to Reproduce

from sklearn import svm
from sklearn.datasets import samples_generator
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_regression
from sklearn.pipeline import Pipeline

# generate some data to play with
X, y = samples_generator.make_classification(
    n_informative=5, n_redundant=0, random_state=42)

anova_filter = SelectKBest(f_regression, k=5)
clf = svm.SVC(kernel='linear')
pipe = Pipeline([('anova', anova_filter), ('svc', clf)])

len(pipe)

Versions

System:
    python: 3.6.7 | packaged by conda-forge | (default, Feb 19 2019, 18:37:23)  [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
executable: /Users/krisz/.conda/envs/arrow36/bin/python
   machine: Darwin-18.2.0-x86_64-i386-64bit

BLAS:
    macros: HAVE_CBLAS=None
  lib_dirs: /Users/krisz/.conda/envs/arrow36/lib
cblas_libs: openblas, openblas

Python deps:
       pip: 19.0.3
setuptools: 40.8.0
   sklearn: 0.21.dev0
     numpy: 1.16.2
     scipy: 1.2.1
    Cython: 0.29.6
    pandas: 0.24.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    EasyWell-defined and straightforward way to resolvehelp wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions