Skip to content

Commit 5d89d9f

Browse files
yu-iskwjkbradley
authored andcommitted
[SPARK-8511] [PYSPARK] Modify a test to remove a saved model in regression.py
[[SPARK-8511] Modify a test to remove a saved model in `regression.py` - ASF JIRA](https://issues.apache.org/jira/browse/SPARK-8511) Author: Yu ISHIKAWA <[email protected]> Closes #6926 from yu-iskw/SPARK-8511 and squashes the following commits: 7cd0948 [Yu ISHIKAWA] Use `shutil.rmtree()` to temporary directories for saving model testings, instead of `os.removedirs()` 4a01c9e [Yu ISHIKAWA] [SPARK-8511][pyspark] Modify a test to remove a saved model in `regression.py`
1 parent ba8a453 commit 5d89d9f

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

python/pyspark/mllib/classification.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ class LogisticRegressionModel(LinearClassificationModel):
135135
1
136136
>>> sameModel.predict(SparseVector(2, {0: 1.0}))
137137
0
138+
>>> from shutil import rmtree
138139
>>> try:
139-
... os.removedirs(path)
140+
... rmtree(path)
140141
... except:
141142
... pass
142143
>>> multi_class_data = [
@@ -387,8 +388,9 @@ class SVMModel(LinearClassificationModel):
387388
1
388389
>>> sameModel.predict(SparseVector(2, {0: -1.0}))
389390
0
391+
>>> from shutil import rmtree
390392
>>> try:
391-
... os.removedirs(path)
393+
... rmtree(path)
392394
... except:
393395
... pass
394396
"""
@@ -515,8 +517,9 @@ class NaiveBayesModel(Saveable, Loader):
515517
>>> sameModel = NaiveBayesModel.load(sc, path)
516518
>>> sameModel.predict(SparseVector(2, {0: 1.0})) == model.predict(SparseVector(2, {0: 1.0}))
517519
True
520+
>>> from shutil import rmtree
518521
>>> try:
519-
... os.removedirs(path)
522+
... rmtree(path)
520523
... except OSError:
521524
... pass
522525
"""

python/pyspark/mllib/clustering.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ class KMeansModel(Saveable, Loader):
7979
>>> sameModel = KMeansModel.load(sc, path)
8080
>>> sameModel.predict(sparse_data[0]) == model.predict(sparse_data[0])
8181
True
82+
>>> from shutil import rmtree
8283
>>> try:
83-
... os.removedirs(path)
84+
... rmtree(path)
8485
... except OSError:
8586
... pass
8687
"""

python/pyspark/mllib/recommendation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ class MatrixFactorizationModel(JavaModelWrapper, JavaSaveable, JavaLoader):
106106
0.4...
107107
>>> sameModel.predictAll(testset).collect()
108108
[Rating(...
109+
>>> from shutil import rmtree
109110
>>> try:
110-
... os.removedirs(path)
111+
... rmtree(path)
111112
... except OSError:
112113
... pass
113114
"""

python/pyspark/mllib/regression.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ class LinearRegressionModel(LinearRegressionModelBase):
133133
True
134134
>>> abs(sameModel.predict(SparseVector(1, {0: 1.0})) - 1) < 0.5
135135
True
136+
>>> from shutil import rmtree
136137
>>> try:
137-
... os.removedirs(path)
138+
... rmtree(path)
138139
... except:
139-
... pass
140+
... pass
140141
>>> data = [
141142
... LabeledPoint(0.0, SparseVector(1, {0: 0.0})),
142143
... LabeledPoint(1.0, SparseVector(1, {0: 1.0})),
@@ -275,8 +276,9 @@ class LassoModel(LinearRegressionModelBase):
275276
True
276277
>>> abs(sameModel.predict(SparseVector(1, {0: 1.0})) - 1) < 0.5
277278
True
279+
>>> from shutil import rmtree
278280
>>> try:
279-
... os.removedirs(path)
281+
... rmtree(path)
280282
... except:
281283
... pass
282284
>>> data = [
@@ -389,8 +391,9 @@ class RidgeRegressionModel(LinearRegressionModelBase):
389391
True
390392
>>> abs(sameModel.predict(SparseVector(1, {0: 1.0})) - 1) < 0.5
391393
True
394+
>>> from shutil import rmtree
392395
>>> try:
393-
... os.removedirs(path)
396+
... rmtree(path)
394397
... except:
395398
... pass
396399
>>> data = [
@@ -500,8 +503,9 @@ class IsotonicRegressionModel(Saveable, Loader):
500503
2.0
501504
>>> sameModel.predict(5)
502505
16.5
506+
>>> from shutil import rmtree
503507
>>> try:
504-
... os.removedirs(path)
508+
... rmtree(path)
505509
... except OSError:
506510
... pass
507511
"""

python/pyspark/mllib/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import tempfile
2525
import array as pyarray
2626
from time import time, sleep
27+
from shutil import rmtree
2728

2829
from numpy import array, array_equal, zeros, inf, all, random
2930
from numpy import sum as array_sum
@@ -398,7 +399,7 @@ def test_classification(self):
398399
self.assertEqual(same_gbt_model.toDebugString(), gbt_model.toDebugString())
399400

400401
try:
401-
os.removedirs(temp_dir)
402+
rmtree(temp_dir)
402403
except OSError:
403404
pass
404405

0 commit comments

Comments
 (0)