Skip to content

Commit 70d7fec

Browse files
committed
FIX workaround bug in numpy 1.9 (scikit-learn#6856)
Also use dtype with explicit precision (as a good practice) although this does not impact the outcome of this test.
1 parent 95c4172 commit 70d7fec

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

sklearn/model_selection/tests/test_validation.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import warnings
66
import tempfile
77
import os
8+
from time import sleep
89

910
import numpy as np
1011
from scipy.sparse import coo_matrix, csr_matrix
@@ -62,6 +63,12 @@
6263
from sklearn.model_selection.tests.test_split import MockClassifier
6364

6465

66+
try:
67+
WindowsError
68+
except NameError:
69+
WindowsError = None
70+
71+
6572
class MockImprovingEstimator(BaseEstimator):
6673
"""Dummy classifier to test the learning curve"""
6774
def __init__(self, n_max_train_sizes):
@@ -781,12 +788,20 @@ def test_score_memmap():
781788
tf = tempfile.NamedTemporaryFile(mode='wb', delete=False)
782789
tf.write(b'Hello world!!!!!')
783790
tf.close()
784-
scores = np.memmap(tf.name, dtype=float)
785-
score = np.memmap(tf.name, shape=(), mode='w+', dtype=float)
791+
scores = np.memmap(tf.name, dtype=np.float64)
792+
score = np.memmap(tf.name, shape=(), mode='r', dtype=np.float64)
786793
try:
787794
cross_val_score(clf, X, y, scoring=lambda est, X, y: score)
788795
# non-scalar should still fail
789796
assert_raises(ValueError, cross_val_score, clf, X, y,
790797
scoring=lambda est, X, y: scores)
791798
finally:
792-
os.unlink(tf.name)
799+
# Best effort to release the mmap file handles before deleting the
800+
# backing file under Windows
801+
scores, score = None, None
802+
for _ in range(3):
803+
try:
804+
os.unlink(tf.name)
805+
break
806+
except WindowsError:
807+
sleep(1.)

0 commit comments

Comments
 (0)