Skip to content

Commit

Permalink
Use shutil.rmtree() to temporary directories for saving model testi…
Browse files Browse the repository at this point in the history
…ngs, instead of `os.removedirs()`
  • Loading branch information
yu-iskw committed Jun 21, 2015
1 parent 4a01c9e commit 7cd0948
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
9 changes: 6 additions & 3 deletions python/pyspark/mllib/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ class LogisticRegressionModel(LinearClassificationModel):
1
>>> sameModel.predict(SparseVector(2, {0: 1.0}))
0
>>> from shutil import rmtree
>>> try:
... os.removedirs(path)
... rmtree(path)
... except:
... pass
>>> multi_class_data = [
Expand Down Expand Up @@ -387,8 +388,9 @@ class SVMModel(LinearClassificationModel):
1
>>> sameModel.predict(SparseVector(2, {0: -1.0}))
0
>>> from shutil import rmtree
>>> try:
... os.removedirs(path)
... rmtree(path)
... except:
... pass
"""
Expand Down Expand Up @@ -515,8 +517,9 @@ class NaiveBayesModel(Saveable, Loader):
>>> sameModel = NaiveBayesModel.load(sc, path)
>>> sameModel.predict(SparseVector(2, {0: 1.0})) == model.predict(SparseVector(2, {0: 1.0}))
True
>>> from shutil import rmtree
>>> try:
... os.removedirs(path)
... rmtree(path)
... except OSError:
... pass
"""
Expand Down
3 changes: 2 additions & 1 deletion python/pyspark/mllib/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class KMeansModel(Saveable, Loader):
>>> sameModel = KMeansModel.load(sc, path)
>>> sameModel.predict(sparse_data[0]) == model.predict(sparse_data[0])
True
>>> from shutil import rmtree
>>> try:
... os.removedirs(path)
... rmtree(path)
... except OSError:
... pass
"""
Expand Down
3 changes: 2 additions & 1 deletion python/pyspark/mllib/recommendation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ class MatrixFactorizationModel(JavaModelWrapper, JavaSaveable, JavaLoader):
0.4...
>>> sameModel.predictAll(testset).collect()
[Rating(...
>>> from shutil import rmtree
>>> try:
... os.removedirs(path)
... rmtree(path)
... except OSError:
... pass
"""
Expand Down
7 changes: 4 additions & 3 deletions python/pyspark/mllib/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class LinearRegressionModel(LinearRegressionModelBase):
True
>>> from shutil import rmtree
>>> try:
... rmtree(path)
... rmtree(path)
... except:
... pass
... pass
>>> data = [
... LabeledPoint(0.0, SparseVector(1, {0: 0.0})),
... LabeledPoint(1.0, SparseVector(1, {0: 1.0})),
Expand Down Expand Up @@ -503,8 +503,9 @@ class IsotonicRegressionModel(Saveable, Loader):
2.0
>>> sameModel.predict(5)
16.5
>>> from shutil import rmtree
>>> try:
... os.removedirs(path)
... rmtree(path)
... except OSError:
... pass
"""
Expand Down
3 changes: 2 additions & 1 deletion python/pyspark/mllib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tempfile
import array as pyarray
from time import time, sleep
from shutil import rmtree

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

try:
os.removedirs(temp_dir)
rmtree(temp_dir)
except OSError:
pass

Expand Down

0 comments on commit 7cd0948

Please sign in to comment.