Skip to content

TST Fix test to actually check writable and readable ndarrays #21853

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

Merged
Merged
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
10 changes: 6 additions & 4 deletions sklearn/metrics/tests/test_dist_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import pickle
import copy

import numpy as np
from numpy.testing import assert_array_almost_equal
Expand Down Expand Up @@ -169,16 +170,17 @@ def check_pdist_bool(metric, D_true):
assert_array_almost_equal(D12, D_true)


@pytest.mark.parametrize("use_read_only_kwargs", [True, False])
@pytest.mark.parametrize("writable_kwargs", [True, False])
@pytest.mark.parametrize("metric_param_grid", METRICS_DEFAULT_PARAMS)
def test_pickle(use_read_only_kwargs, metric_param_grid):
def test_pickle(writable_kwargs, metric_param_grid):
metric, param_grid = metric_param_grid
keys = param_grid.keys()
for vals in itertools.product(*param_grid.values()):
if use_read_only_kwargs:
if any(isinstance(val, np.ndarray) for val in vals):
vals = copy.deepcopy(vals)
for val in vals:
if isinstance(val, np.ndarray):
val.setflags(write=False)
val.setflags(write=writable_kwargs)
kwargs = dict(zip(keys, vals))
check_pickle(metric, kwargs)

Expand Down