Skip to content

Commit

Permalink
TST Extend tests for scipy.sparse.*array in `sklearn/tests/test_pip…
Browse files Browse the repository at this point in the history
…eline.py` (scikit-learn#27278)
  • Loading branch information
rprkh authored Sep 11, 2023
1 parent 3dd4906 commit 4b87997
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sklearn/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import joblib
import numpy as np
import pytest
from scipy import sparse

from sklearn.base import BaseEstimator, TransformerMixin, clone, is_classifier
from sklearn.cluster import KMeans
Expand Down Expand Up @@ -46,6 +45,7 @@
assert_array_almost_equal,
assert_array_equal,
)
from sklearn.utils.fixes import CSR_CONTAINERS
from sklearn.utils.validation import check_is_fitted

iris = load_iris()
Expand Down Expand Up @@ -485,7 +485,8 @@ def test_predict_methods_with_predict_params(method_name):
assert pipe.named_steps["clf"].got_attribute


def test_feature_union():
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
def test_feature_union(csr_container):
# basic sanity check for feature union
X = iris.data
X -= X.mean(axis=0)
Expand All @@ -504,7 +505,7 @@ def test_feature_union():
# test if it also works for sparse input
# We use a different svd object to control the random_state stream
fs = FeatureUnion([("svd", svd), ("select", select)])
X_sp = sparse.csr_matrix(X)
X_sp = csr_container(X)
X_sp_transformed = fs.fit_transform(X_sp, y)
assert_array_almost_equal(X_transformed, X_sp_transformed.toarray())

Expand Down

0 comments on commit 4b87997

Please sign in to comment.