Skip to content

Commit 7cd0948

Browse files
committed
Use shutil.rmtree() to temporary directories for saving model testings, instead of os.removedirs()
1 parent 4a01c9e commit 7cd0948

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ class LinearRegressionModel(LinearRegressionModelBase):
135135
True
136136
>>> from shutil import rmtree
137137
>>> try:
138-
... rmtree(path)
138+
... rmtree(path)
139139
... except:
140-
... pass
140+
... pass
141141
>>> data = [
142142
... LabeledPoint(0.0, SparseVector(1, {0: 0.0})),
143143
... LabeledPoint(1.0, SparseVector(1, {0: 1.0})),
@@ -503,8 +503,9 @@ class IsotonicRegressionModel(Saveable, Loader):
503503
2.0
504504
>>> sameModel.predict(5)
505505
16.5
506+
>>> from shutil import rmtree
506507
>>> try:
507-
... os.removedirs(path)
508+
... rmtree(path)
508509
... except OSError:
509510
... pass
510511
"""

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)