Skip to content

Commit f917b39

Browse files
committed
disable unit test on old version of scikit-learn
1 parent e405447 commit f917b39

File tree

6 files changed

+117
-24
lines changed

6 files changed

+117
-24
lines changed

_cmake/finalize.cmake

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,46 @@ else()
99
config_content_cuda "HAS_CUDA = 0")
1010
endif()
1111

12+
execute_process(
13+
COMMAND ${Python3_EXECUTABLE} -c "import cython;print(cython.__version__)"
14+
OUTPUT_VARIABLE CYTHON_VERSION
15+
ERROR_VARIABLE CYTHON_version_error
16+
RESULT_VARIABLE CYTHON_version_result
17+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
18+
19+
execute_process(
20+
COMMAND ${Python3_EXECUTABLE} -c "import sklearn;print(sklearn.__version__)"
21+
OUTPUT_VARIABLE SKLEARN_VERSION
22+
ERROR_VARIABLE SKLEARN_version_error
23+
RESULT_VARIABLE SKLEARN_version_result
24+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
25+
26+
execute_process(
27+
COMMAND ${Python3_EXECUTABLE} -c "import numpy;print(numpy.__version__)"
28+
OUTPUT_VARIABLE NUMPY_VERSION
29+
ERROR_VARIABLE NUMPY_version_error
30+
RESULT_VARIABLE NUMPY_version_result
31+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
32+
33+
execute_process(
34+
COMMAND ${Python3_EXECUTABLE} -c "import scipy;print(scipy.__version__)"
35+
OUTPUT_VARIABLE SCIPY_VERSION
36+
ERROR_VARIABLE SCIPY_version_error
37+
RESULT_VARIABLE SCIPY_version_result
38+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_STRIP_TRAILING_WHITESPACE)
39+
1240
set(
1341
config_content_comma
1442
"${config_content_cuda}"
1543
"\nCXX_FLAGS = '${CMAKE_CXX_FLAGS}'"
1644
"\nCMAKE_CXX_STANDARD_REQUIRED = '${CMAKE_CXX_STANDARD_REQUIRED}'"
1745
"\nCMAKE_CXX_EXTENSIONS = '${CMAKE_CXX_EXTENSIONS}'"
18-
"\nCMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}\n")
46+
"\nCMAKE_CXX_STANDARD = ${CMAKE_CXX_STANDARD}"
47+
"\n\n# Was compiled with the following versions."
48+
"\nCYTHON_VERSION = '${CYTHON_VERSION}'"
49+
"\nSKLEARN_VERSION = '${SKLEARN_VERSION}'"
50+
"\nNUMPY_VERSION = '${NUMPY_VERSION}'"
51+
"\nSCIPY_VERSION = '${SCIPY_VERSION}'"
52+
"\n")
1953

2054
string(REPLACE ";" "" config_content "${config_content_comma}")

_unittests/ut_mlmodel/test_piecewise_decision_tree_experiment.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# -*- coding: utf-8 -*-
22
import unittest
33
import warnings
4+
import packaging.version as pv
45
import numpy
56
from sklearn.tree._criterion import MSE
67
from sklearn.tree import DecisionTreeRegressor
7-
from sklearn import datasets
8+
from sklearn import datasets, __version__ as skl_ver
89
from mlinsights.ext_test_case import ExtTestCase
910
from mlinsights.mlmodel.piecewise_tree_regression import PiecewiseTreeRegressor
1011

@@ -17,6 +18,10 @@ class TestPiecewiseDecisionTreeExperiment(ExtTestCase):
1718
# may indicate binary incompatibility.
1819
# Expected 1360 from C header, got 1576 from PyObject
1920
# )
21+
@unittest.skipIf(
22+
pv.Version(skl_ver) < pv.Version("1.3.3"),
23+
reason="it works with the main branch and the same cython",
24+
)
2025
def test_criterions(self):
2126
with warnings.catch_warnings(record=True) as w:
2227
warnings.simplefilter("always")
@@ -178,6 +183,10 @@ def test_criterions(self):
178183
) # 0 if the function is not called
179184
self.assertAlmostEqual(expected_p2[i - 2], p2, atol=1e-10)
180185

186+
@unittest.skipIf(
187+
pv.Version(skl_ver) < pv.Version("1.3.3"),
188+
reason="it works with the main branch and the same cython",
189+
)
181190
def test_decision_tree_criterion(self):
182191
from mlinsights.mlmodel.piecewise_tree_regression_criterion import (
183192
SimpleRegressorCriterion,
@@ -218,6 +227,10 @@ def test_decision_tree_criterion(self):
218227
self.assertEqual(p1, p2)
219228
self.assertEqual(clr1.tree_.node_count, clr2.tree_.node_count)
220229

230+
@unittest.skipIf(
231+
pv.Version(skl_ver) < pv.Version("1.3.3"),
232+
reason="it works with the main branch and the same cython",
233+
)
221234
def test_decision_tree_criterion_iris(self):
222235
from mlinsights.mlmodel.piecewise_tree_regression_criterion import (
223236
SimpleRegressorCriterion,
@@ -237,6 +250,10 @@ def test_decision_tree_criterion_iris(self):
237250
p2 = clr2.predict(X)
238251
self.assertEqual(p1[:10], p2[:10])
239252

253+
@unittest.skipIf(
254+
pv.Version(skl_ver) < pv.Version("1.3.3"),
255+
reason="it works with the main branch and the same cython",
256+
)
240257
def test_decision_tree_criterion_iris_dtc(self):
241258
iris = datasets.load_iris()
242259
X, y = iris.data, iris.target

_unittests/ut_mlmodel/test_piecewise_decision_tree_experiment_fast.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import unittest
33
import warnings
44
import numpy
5+
import packaging.version as pv
56
from sklearn.tree._criterion import MSE
67
from sklearn.tree import DecisionTreeRegressor
7-
from sklearn import datasets
8+
from sklearn import datasets, __version__ as skl_ver
89
from mlinsights.ext_test_case import ExtTestCase
910
from mlinsights.mlmodel.piecewise_tree_regression import PiecewiseTreeRegressor
1011

@@ -28,10 +29,10 @@
2829

2930

3031
class TestPiecewiseDecisionTreeExperimentFast(ExtTestCase):
31-
# @unittest.skip(
32-
# reason="self.y = y raises: Fatal Python error: "
33-
# "__pyx_fatalerror: Acquisition count is"
34-
# )
32+
@unittest.skipIf(
33+
pv.Version(skl_ver) < pv.Version("1.3.3"),
34+
reason="it works with the main branch and the same cython",
35+
)
3536
def test_criterions(self):
3637
X = numpy.array([[1.0, 2.0]]).T
3738
y = numpy.array([1.0, 2.0])
@@ -145,6 +146,10 @@ def test_criterions(self):
145146
p2 = _test_criterion_impurity_improvement(c2, 0.0, left2, right2)
146147
self.assertAlmostEqual(p1, p2)
147148

149+
@unittest.skipIf(
150+
pv.Version(skl_ver) < pv.Version("1.3.3"),
151+
reason="it works with the main branch and the same cython",
152+
)
148153
def test_decision_tree_criterion_fast(self):
149154
X = numpy.array([[1.0, 2.0, 10.0, 11.0]]).T
150155
y = numpy.array([0.9, 1.1, 1.9, 2.1])
@@ -159,6 +164,10 @@ def test_decision_tree_criterion_fast(self):
159164
self.assertEqual(p1, p2)
160165
self.assertEqual(clr1.tree_.node_count, clr2.tree_.node_count)
161166

167+
@unittest.skipIf(
168+
pv.Version(skl_ver) < pv.Version("1.3.3"),
169+
reason="it works with the main branch and the same cython",
170+
)
162171
def test_decision_tree_criterion_iris(self):
163172
iris = datasets.load_iris()
164173
X, y = iris.data, iris.target
@@ -172,6 +181,10 @@ def test_decision_tree_criterion_iris(self):
172181
p2 = clr2.predict(X)
173182
self.assertEqual(p1[:10], p2[:10])
174183

184+
@unittest.skipIf(
185+
pv.Version(skl_ver) < pv.Version("1.3.3"),
186+
reason="it works with the main branch and the same cython",
187+
)
175188
def test_decision_tree_criterion_iris_dtc(self):
176189
iris = datasets.load_iris()
177190
X, y = iris.data, iris.target

_unittests/ut_mlmodel/test_piecewise_decision_tree_experiment_linear.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import unittest
33
import warnings
44
import numpy
5+
import packaging.version as pv
56
from sklearn.tree._criterion import MSE
67
from sklearn.tree import DecisionTreeRegressor
7-
from sklearn import datasets
8+
from sklearn import datasets, __version__ as skl_ver
89
from sklearn.model_selection import train_test_split
910
from mlinsights.ext_test_case import ExtTestCase
1011
from mlinsights.mlmodel.piecewise_tree_regression import PiecewiseTreeRegressor
@@ -26,10 +27,10 @@
2627

2728

2829
class TestPiecewiseDecisionTreeExperimentLinear(ExtTestCase):
29-
# @unittest.skip(
30-
# reason="self.y = y raises: Fatal Python error: "
31-
# "__pyx_fatalerror: Acquisition count is"
32-
# )
30+
@unittest.skipIf(
31+
pv.Version(skl_ver) < pv.Version("1.3.3"),
32+
reason="it works with the main branch and the same cython",
33+
)
3334
def test_criterions(self):
3435
X = numpy.array([[10.0, 12.0, 13.0]]).T
3536
y = numpy.array([20.0, 22.0, 23.0])
@@ -131,10 +132,10 @@ def test_criterions(self):
131132
self.assertGreater(dest[0], 0)
132133
self.assertGreater(dest[1], 0)
133134

134-
# @unittest.skip(
135-
# reason="self.y = y raises: Fatal Python error: "
136-
# "__pyx_fatalerror: Acquisition count is"
137-
# )
135+
@unittest.skipIf(
136+
pv.Version(skl_ver) < pv.Version("1.3.3"),
137+
reason="it works with the main branch and the same cython",
138+
)
138139
def test_criterions_check_value(self):
139140
X = numpy.array([[10.0, 12.0, 13.0]]).T
140141
y = numpy.array([[20.0, 22.0, 23.0]]).T
@@ -143,6 +144,10 @@ def test_criterions_check_value(self):
143144
c2.node_beta(coef)
144145
self.assertEqual(coef[:2], numpy.array([1, 10]))
145146

147+
@unittest.skipIf(
148+
pv.Version(skl_ver) < pv.Version("1.3.3"),
149+
reason="it works with the main branch and the same cython",
150+
)
146151
def test_decision_tree_criterion_linear(self):
147152
X = numpy.array([[1.0, 2.0, 10.0, 11.0]]).T
148153
y = numpy.array([0.9, 1.1, 1.9, 2.1])
@@ -157,6 +162,10 @@ def test_decision_tree_criterion_linear(self):
157162
self.assertEqual(p1, p2)
158163
self.assertEqual(clr1.tree_.node_count, clr2.tree_.node_count)
159164

165+
@unittest.skipIf(
166+
pv.Version(skl_ver) < pv.Version("1.3.3"),
167+
reason="it works with the main branch and the same cython",
168+
)
160169
def test_decision_tree_criterion_iris(self):
161170
iris = datasets.load_iris()
162171
X, y = iris.data, iris.target
@@ -168,10 +177,10 @@ def test_decision_tree_criterion_iris(self):
168177
p2 = clr2.predict(X)
169178
self.assertEqual(p1.shape, p2.shape)
170179

171-
# @unittest.skip(
172-
# reason="self.y = y raises: Fatal Python error: "
173-
# "__pyx_fatalerror: Acquisition count is"
174-
# )
180+
@unittest.skipIf(
181+
pv.Version(skl_ver) < pv.Version("1.3.3"),
182+
reason="it works with the main branch and the same cython",
183+
)
175184
def test_decision_tree_criterion_iris_dtc(self):
176185
iris = datasets.load_iris()
177186
X, y = iris.data, iris.target
@@ -195,10 +204,10 @@ def test_decision_tree_criterion_iris_dtc(self):
195204
self.assertIsInstance(mp, dict)
196205
self.assertGreater(len(mp), 2)
197206

198-
# @unittest.skip(
199-
# reason="self.y = y raises: Fatal Python error: "
200-
# "__pyx_fatalerror: Acquisition count is"
201-
# )
207+
@unittest.skipIf(
208+
pv.Version(skl_ver) < pv.Version("1.3.3"),
209+
reason="it works with the main branch and the same cython",
210+
)
202211
def test_decision_tree_criterion_iris_dtc_traintest(self):
203212
iris = datasets.load_iris()
204213
X, y = iris.data, iris.target
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from mlinsights.ext_test_case import ExtTestCase
3+
from mlinsights._config import CYTHON_VERSION
4+
5+
6+
class TestCheckVersion(ExtTestCase):
7+
def test_version_cython(self):
8+
self.assertVersionGreaterOrEqual(CYTHON_VERSION, "3.0.5")
9+
10+
11+
if __name__ == "__main__":
12+
unittest.main(verbosity=2)

mlinsights/ext_test_case.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ def assertEndsWith(self, suffix: str, text: str):
327327
if not text.endswith(suffix):
328328
raise AssertionError(f"Unable to find {suffix!r} in {text!r}.")
329329

330+
def assertVersionGreaterOrEqual(self, v1, v2):
331+
from packaging.version import Version
332+
333+
if Version(v1) < Version(v2):
334+
raise AssertionError(
335+
f"Unexpected version, condition {v1} >= {v2} is not true."
336+
)
337+
330338
@classmethod
331339
def tearDownClass(cls):
332340
for name, line, w in cls._warns:

0 commit comments

Comments
 (0)