Skip to content

Commit a7a15bf

Browse files
committed
Minmal fix to remove side effects in sklearn/tests/test_pipeline.py
1 parent b5859b8 commit a7a15bf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sklearn/tests/test_pipeline.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@
5252
from sklearn.utils.fixes import CSR_CONTAINERS
5353
from sklearn.utils.validation import check_is_fitted
5454

55+
# Load a shared tests data sets for the tests in this module. Mark them
56+
# read-only to avoid unintentional in-place modifications that would introduce
57+
# side-effects between tests.
5558
iris = load_iris()
59+
iris.data.flags.writeable = False
60+
iris.target.flags.writeable = False
61+
5662

5763
JUNK_FOOD_DOCS = (
5864
"the pizza pizza beer copyright",
@@ -499,7 +505,7 @@ def test_predict_methods_with_predict_params(method_name):
499505
@pytest.mark.parametrize("csr_container", CSR_CONTAINERS)
500506
def test_feature_union(csr_container):
501507
# basic sanity check for feature union
502-
X = iris.data
508+
X = iris.data.copy()
503509
X -= X.mean(axis=0)
504510
y = iris.target
505511
svd = TruncatedSVD(n_components=2, random_state=0)
@@ -1584,7 +1590,7 @@ def fit(self, X, y=None, **fit_params):
15841590
def test_pipeline_missing_values_leniency():
15851591
# check that pipeline let the missing values validation to
15861592
# the underlying transformers and predictors.
1587-
X, y = iris.data, iris.target
1593+
X, y = iris.data.copy(), iris.target.copy()
15881594
mask = np.random.choice([1, 0], X.shape, p=[0.1, 0.9]).astype(bool)
15891595
X[mask] = np.nan
15901596
pipe = make_pipeline(SimpleImputer(), LogisticRegression())

0 commit comments

Comments
 (0)