Skip to content

Commit 989650d

Browse files
author
Louiszr
committed
Fixed copy() to copy models instead of list
1 parent 17f99d4 commit 989650d

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

python/pyspark/ml/tests/test_tuning.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def test_copy(self):
125125
'foo',
126126
"Changing the original avgMetrics should not affect the copied model"
127127
)
128-
cvModel.subModels[0] = 'foo'
128+
cvModel.subModels[0][0].getInducedError = lambda: 'foo'
129129
self.assertNotEqual(
130-
cvModelCopied.subModels[0],
130+
cvModelCopied.subModels[0][0].getInducedError(),
131131
'foo',
132132
"Changing the original subModels should not affect the copied model"
133133
)
@@ -777,9 +777,9 @@ def test_copy(self):
777777
'foo',
778778
"Changing the original validationMetrics should not affect the copied model"
779779
)
780-
tvsModel.subModels[0] = 'foo'
780+
tvsModel.subModels[0].getInducedError = lambda: 'foo'
781781
self.assertNotEqual(
782-
tvsModelCopied.subModels[0],
782+
tvsModelCopied.subModels[0].getInducedError(),
783783
'foo',
784784
"Changing the original subModels should not affect the copied model"
785785
)

python/pyspark/ml/tuning.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,10 @@ def copy(self, extra=None):
480480
extra = dict()
481481
bestModel = self.bestModel.copy(extra)
482482
avgMetrics = list(self.avgMetrics)
483-
subModels = [model.copy() for model in self.subModels]
483+
subModels = [
484+
[sub_model.copy() for sub_model in fold_sub_models]
485+
for fold_sub_models in self.subModels
486+
]
484487
return self._copyValues(CrossValidatorModel(bestModel, avgMetrics, subModels), extra=extra)
485488

486489
@since("2.3.0")

0 commit comments

Comments
 (0)