Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b06a7d2

Browse files
authored
FIX Pop unnecessary elements from metric_kwargs in datasets_pair.pyx.tp (#26987)
1 parent 43dbec5 commit b06a7d2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sklearn/metrics/_pairwise_distances_reduction/_datasets_pair.pyx.tp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import copy
2+
13
{{py:
24

35
implementation_specific_values = [
@@ -84,12 +86,17 @@ cdef class DatasetsPair{{name_suffix}}:
8486
datasets_pair: DatasetsPair{{name_suffix}}
8587
The suited DatasetsPair{{name_suffix}} implementation.
8688
"""
87-
# Y_norm_squared might be propagated down to DatasetsPairs
88-
# via metrics_kwargs when the Euclidean specialisations
89-
# can't be used. To prevent Y_norm_squared to be passed
89+
# X_norm_squared and Y_norm_squared might be propagated
90+
# down to DatasetsPairs via metrics_kwargs when the Euclidean
91+
# specialisations can't be used.
92+
# To prevent X_norm_squared and Y_norm_squared to be passed
9093
# down to DistanceMetrics (whose constructors would raise
91-
# a RuntimeError), we pop it here.
94+
# a RuntimeError), we pop them here.
9295
if metric_kwargs is not None:
96+
# Copying metric_kwargs not to pop "X_norm_squared"
97+
# and "Y_norm_squared" where they are used
98+
metric_kwargs = copy.copy(metric_kwargs)
99+
metric_kwargs.pop("X_norm_squared", None)
93100
metric_kwargs.pop("Y_norm_squared", None)
94101
cdef:
95102
{{DistanceMetric}} distance_metric = DistanceMetric.get_metric(

0 commit comments

Comments
 (0)